-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bugfix/bai 367 user receives no feedback #619
Conversation
frontend/pages/review.tsx
Outdated
setOpen(false) | ||
await postEndpoint(`/api/v1/approval/${approval?._id}/respond`, { choice }).then((res) => { | ||
if (res.status !== 200) { | ||
console.log(res) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove console log
frontend/pages/review.tsx
Outdated
if (res.status !== 200) { | ||
console.log(res) | ||
res.json().then((errorResponse) => { | ||
console.log(errorResponse) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And this
frontend/pages/review.tsx
Outdated
mutateNumApprovals() | ||
setOpen(false) | ||
await postEndpoint(`/api/v1/approval/${approval?._id}/respond`, { choice }).then((res) => { | ||
if (res.status !== 200) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's safer to check >= 400
. All 2xx and 3xx responses are successes.
frontend/pages/review.tsx
Outdated
setOpen(false) | ||
await postEndpoint(`/api/v1/approval/${approval?._id}/respond`, { choice }).then((res) => { | ||
if (res.status !== 200) { | ||
res.json().then((errorResponse) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make this an async function, then you can write
const errorResponse = await res.json()
setShowAlert(true)
setErrorMessage(errorResponse.message)
Which is generally clearer.
frontend/pages/review.tsx
Outdated
setOpen(false) | ||
await postEndpoint(`/api/v1/approval/${approval?._id}/respond`, { choice }).then(async (res) => { | ||
if (res.status >= 400) { | ||
const errorResponse = await res.json() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This catches every SERVER error. E.g. 'Approval cannot be found'. It does not handle NETWORK errors. E.g. 'Could not reach server'.
There is a getErrorMessage
exported from utils/fetcher
which should be used instead. If can handle more errors.
Instead of:
const errorResponse = await res.json()
It's:
const errorResponse = await getErrorMessage(res)
In the event of the backend being broken, whilst the user tries to approve/reject a model, an error message has been implemented to give the user feedback that it is broken.