Skip to content
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

Merged
merged 8 commits into from
Jul 18, 2023

Conversation

TT38665
Copy link
Member

@TT38665 TT38665 commented Jul 12, 2023

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.

setOpen(false)
await postEndpoint(`/api/v1/approval/${approval?._id}/respond`, { choice }).then((res) => {
if (res.status !== 200) {
console.log(res)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove console log

if (res.status !== 200) {
console.log(res)
res.json().then((errorResponse) => {
console.log(errorResponse)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this

mutateNumApprovals()
setOpen(false)
await postEndpoint(`/api/v1/approval/${approval?._id}/respond`, { choice }).then((res) => {
if (res.status !== 200) {
Copy link
Member

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.

setOpen(false)
await postEndpoint(`/api/v1/approval/${approval?._id}/respond`, { choice }).then((res) => {
if (res.status !== 200) {
res.json().then((errorResponse) => {
Copy link
Member

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.

setOpen(false)
await postEndpoint(`/api/v1/approval/${approval?._id}/respond`, { choice }).then(async (res) => {
if (res.status >= 400) {
const errorResponse = await res.json()
Copy link
Member

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)

@TT38665 TT38665 merged commit 304a4ab into main Jul 18, 2023
@TT38665 TT38665 deleted the bugfix/BAI-367-user-receives-no-feedback branch July 26, 2023 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants