Skip to content

Commit

Permalink
Data refetch in case of internal server error
Browse files Browse the repository at this point in the history
  • Loading branch information
fmata97 committed Feb 6, 2024
1 parent 1210c2e commit 9d9d1da
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 23 deletions.
2 changes: 1 addition & 1 deletion frontend/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function App() {
} else if (err.response.status === 403) {
// AxiosError, sv responded with 4xx
showErrorMsg("Successfully authenticated via FenixEdu but not authorized in the system");
} else if (("" + err.response.status)[0] === "5") {
} else if (String(err.response.status).startsWith("5")) {
// Internal sv error
showErrorMsg("Authentication failed. Internal server error");
}
Expand Down
11 changes: 9 additions & 2 deletions frontend/src/components/NewProjectBtn.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,15 @@ export default function NewProjectBtn({ refetch }) {

let msg = "Couldn't create project";
if (err.reqTimedOut) msg += ". Request timed out";
else if (err.response)
msg += `. ${("" + err.response.status)[0] === "4" ? "Bad client request" : "Internal server error"}`;
else if (err.response) {
const status = String(err.response.status);
if (status.startsWith("4")) {
msg += ". Bad client request";
} else if (status.startsWith("5")) {
msg += ". Internal server error";
refetch();
}
}

showErrorMsg(msg);
})
Expand Down
11 changes: 9 additions & 2 deletions frontend/src/components/NewReminderBtn.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,15 @@ function NewReminderBtn({ refetch }) {

let msg = "Couldn't create reminder";
if (err.reqTimedOut) msg += ". Request timed out";
else if (err.response)
msg += `. ${("" + err.response.status)[0] === "4" ? "Bad client request" : "Internal server error"}`;
else if (err.response) {
const status = String(err.response.status);
if (status.startsWith("4")) {
msg += ". Bad client request";
} else if (status.startsWith("5")) {
msg += ". Internal server error";
refetch();
}
}

showErrorMsg(msg);
})
Expand Down
11 changes: 9 additions & 2 deletions frontend/src/components/NewTransactionBtn.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,15 @@ export default function NewTransactionBtn({ refetch, projectsList }) {

let msg = "Couldn't create transaction";
if (err.reqTimedOut) msg += ". Request timed out";
else if (err.response)
msg += `. ${("" + err.response.status)[0] === "4" ? "Bad client request" : "Internal server error"}`;
else if (err.response) {
const status = String(err.response.status);
if (status.startsWith("4")) {
msg += ". Bad client request";
} else if (status.startsWith("5")) {
msg += ". Internal server error";
refetch();
}
}

showErrorMsg(msg);
})
Expand Down
11 changes: 9 additions & 2 deletions frontend/src/components/NewUserBtn.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,15 @@ function NewUserBtn({ refetch }) {

let msg = "Couldn't create user";
if (err.reqTimedOut) msg += ". Request timed out";
else if (err.response)
msg += `. ${("" + err.response.status)[0] === "4" ? "Bad client request" : "Internal server error"}`;
else if (err.response) {
const status = String(err.response.status);
if (status.startsWith("4")) {
msg += ". Bad client request";
} else if (status.startsWith("5")) {
msg += ". Internal server error";
refetch();
}
}

showErrorMsg(msg);
})
Expand Down
11 changes: 9 additions & 2 deletions frontend/src/components/ProjectsEditModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,15 @@ function ProjectEditModal({ open, setOpen, project, refetch }) {

let msg = "Couldn't update Project";
if (err.reqTimedOut) msg += ". Request timed out";
else if (err.response)
msg += `. ${("" + err.response.status)[0] === "4" ? "Bad client request" : "Internal server error"}`;
else if (err.response) {
const status = String(err.response.status);
if (status.startsWith("4")) {
msg += ". Bad client request";
} else if (status.startsWith("5")) {
msg += ". Internal server error";
refetch();
}
}

showErrorMsg(msg);
})
Expand Down
11 changes: 9 additions & 2 deletions frontend/src/components/ReminderEditModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,15 @@ function ReminderEditModal({ open, setOpen, reminder, refetch }) {

let msg = "Couldn't update Reminder";
if (err.reqTimedOut) msg += ". Request timed out";
else if (err.response)
msg += `. ${("" + err.response.status)[0] === "4" ? "Bad client request" : "Internal server error"}`;
else if (err.response) {
const status = String(err.response.status);
if (status.startsWith("4")) {
msg += ". Bad client request";
} else if (status.startsWith("5")) {
msg += ". Internal server error";
refetch();
}
}

showErrorMsg(msg);
})
Expand Down
11 changes: 9 additions & 2 deletions frontend/src/components/TransactionEditModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,15 @@ function TransactionEditModal({ open, setOpen, transaction, refetch, projectsLis

let msg = "Couldn't update Transaction";
if (err.reqTimedOut) msg += ". Request timed out";
else if (err.response)
msg += `. ${("" + err.response.status)[0] === "4" ? "Bad client request" : "Internal server error"}`;
else if (err.response) {
const status = String(err.response.status);
if (status.startsWith("4")) {
msg += ". Bad client request";
} else if (status.startsWith("5")) {
msg += ". Internal server error";
refetch();
}
}

showErrorMsg(msg);
})
Expand Down
11 changes: 9 additions & 2 deletions frontend/src/pages/Dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,15 @@ function DashboardPage() {

let msg = `Couldn't delete reminder ${reminderToDelete.id}`;
if (err.reqTimedOut) msg += ". Request timed out";
else if (err.response)
msg += `. ${("" + err.response.status)[0] === "4" ? "Bad client request" : "Internal server error"}`;
else if (err.response) {
const status = String(err.response.status);
if (status.startsWith("4")) {
msg += ". Bad client request";
} else if (status.startsWith("5")) {
msg += ". Internal server error";
refetchReminders();
}
}

showErrorMsg(msg);
});
Expand Down
11 changes: 9 additions & 2 deletions frontend/src/pages/Projects.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,15 @@ function ProjectsPage() {

let msg = `Couldn't delete project ${projectToDelete.name}`;
if (err.reqTimedOut) msg += ". Request timed out";
else if (err.response)
msg += `. ${("" + err.response.status)[0] === "4" ? "Bad client request" : "Internal server error"}`;
else if (err.response) {
const status = String(err.response.status);
if (status.startsWith("4")) {
msg += ". Bad client request";
} else if (status.startsWith("5")) {
msg += ". Internal server error";
refetchProjects();
}
}

showErrorMsg(msg);
});
Expand Down
11 changes: 9 additions & 2 deletions frontend/src/pages/Settings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,15 @@ function SettingsPage() {

let msg = `Couldn't revoke ${userToDelete.username}'s access`;
if (err.reqTimedOut) msg += ". Request timed out";
else if (err.response)
msg += `. ${("" + err.response.status)[0] === "4" ? "Bad client request" : "Internal server error"}`;
else if (err.response) {
const status = String(err.response.status);
if (status.startsWith("4")) {
msg += ". Bad client request";
} else if (status.startsWith("5")) {
msg += ". Internal server error";
refetchUsers();
}
}

showErrorMsg(msg);
});
Expand Down
11 changes: 9 additions & 2 deletions frontend/src/pages/Transactions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,15 @@ function TransactionsPage() {

let msg = `Couldn't delete transaction ${transactionToDelete.id}`;
if (err.reqTimedOut) msg += ". Request timed out";
else if (err.response)
msg += `. ${("" + err.response.status)[0] === "4" ? "Bad client request" : "Internal server error"}`;
else if (err.response) {
const status = String(err.response.status);
if (status.startsWith("4")) {
msg += ". Bad client request";
} else if (status.startsWith("5")) {
msg += ". Internal server error";
refetchTransactions();
}
}

showErrorMsg(msg);
});
Expand Down

0 comments on commit 9d9d1da

Please sign in to comment.