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

Handle API errors on the frontend #152

Open
5 tasks done
rodmaia opened this issue Feb 23, 2021 · 8 comments · May be fixed by #175
Open
5 tasks done

Handle API errors on the frontend #152

rodmaia opened this issue Feb 23, 2021 · 8 comments · May be fixed by #175
Assignees
Labels
API documentation Improvements or additions to documentation frontend

Comments

@rodmaia
Copy link
Collaborator

rodmaia commented Feb 23, 2021

The API handles errors on all operations (see #42). Those errors need to be handled appropriately on the frontend so people understand why things failed and how they can recover.

Keep in mind that the API and BotFlow are separate projects so they can evolve separately. Proper communication and error handling should be enforced by the code, not by product management.

See also #48

Tasks

  • List all possible errors and their causes
  • Analise what errors can be prevented with changes in app behavior. Open issues for those changes
  • Write error messages for the errors that cannot be prevented and display them in the app with the appropriate level of visual importance

Acceptance criteria

  • All API errors are handled
  • Users are not left without proper feedback
@rodmaia rodmaia changed the title Revisar respostas da API (#42) e tratar respostas de erro no front Handle API errors on the frontend Feb 23, 2021
@Miguel-Alves Miguel-Alves self-assigned this Mar 4, 2021
@Miguel-Alves Miguel-Alves added the documentation Improvements or additions to documentation label Mar 25, 2021
@Miguel-Alves
Copy link
Collaborator

Miguel-Alves commented Mar 25, 2021

@rodmaia, I ran through the entire API to catalog all the errors. @luderibeiro helped me to create a document containing all the errors and their causes.

Where can I add this document? Is it desirable that the wiki or readme contains this info?

And about the changes in app behaviour, what is the extension of them?

@Miguel-Alves
Copy link
Collaborator

 

Endpoint

Method

Response Status Code

Error message

Error cause

/intents

GET

200

-

Not an error

404

-

Could not found the object of the request / The page is unvaliable

POST

201

-

Not an error

400

‘Missing keys’

There is a key missing or both of them.

‘name’ or ‘samples’

‘Name should contain no special characters other than underscore’

The user added a invalid character to the ‘name’

‘There should be at least one sample’

There are no valid samples provided

404

-

Could not found the object of the request/ The page is unvaliable

DELETE

204

-

Not an error

404

-

Could not found the object of the request/ The page is unvaliable

PUT

200

-

Not an error

400

‘Missing keys’

There is a key missing or both of them.

‘name’ or ‘samples’

‘Name should contain no special characters other than underscore’

The user added a invalid character to the ‘name’

‘There should be at least one sample’

There are no valid samples provided

404

-

Could not found the object of the request/ The page is unvaliable

 

 

Endpoint

Method

Response Status Code

Error message

Error cause

/utters

GET

200

-

Not an error

404

-

Could not found the object of the request / The page is unvaliable

POST

201

-

Not an error

400

‘Missing keys’

At least one of ‘name’, ‘multiple_alternatives’ or ‘alternatives’ is not provided

‘Name should contain no special characters other than underscore’

The user added a invalid character to the ‘name’

‘Multiple alternatives field should be a boolean’

This error has a strange way to happen. It considers that the ‘multiple_alternatives’ parameter is not a boolean. But, through normal usage of the app, this is not possible. This error helps to protect the app of breaking through bad intentional usage of its endpoints.

‘Invalid alternatives’

No utter content was provided

404

-

Could not found the object of the request / The page is unvaliable

DELETE

204

-

Not an error

404

-

Could not found the object of the request / The page is unvaliable

PUT

200

-

Not an error

400

‘Missing keys’

At least one of ‘name’, ‘multiple_alternatives’ or ‘alternatives’ is not provided

‘Name should contain no special characters other than underscore’

The user added a invalid character to the ‘name’

‘Multiple alternatives field should be a boolean’

This error has a strange way to happen. It considers that the ‘multiple_alternatives’ parameter is not a boolean. But, through normal usage of the app, this is not possible. This error helps to protect the app of breaking through bad intentional usage of its endpoints.

‘Invalid alternatives’

No utter content was provided

404

-

Could not found the object of the request / The page is unvaliable

 

Endpoint

Method

Response Status Code

Error message

Error cause

/stories

GET

200

-

Not an error

404

-

Could not found the object of the request / The page is unvaliable

POST

201

-

Not an error

400

‘Invalid data’

No stories content was provided

‘Invalid content array’

The content provided doesnt have the correct form

404

-

Could not found the object of the request / The page is unvaliable

DELETE

204

-

Not an error

404

-

Could not found the object of the request / The page is unvaliable

PUT

200

-

Not an error

400

‘Invalid data’

No stories content was provided

‘Invalid content array’

The content provided doesnt have the correct form

404

-

Could not found the object of the request / The page is unvaliable

 

@rodmaia
Copy link
Collaborator Author

rodmaia commented Mar 26, 2021

@rodmaia, I ran through the entire API to catalog all the errors. @luderibeiro helped me to create a document containing all the errors and their causes.

Good job! Accidentally, you did part the job of #48.

Where can I add this document? Is it desirable that the wiki or readme contains this info?

The wiki should be a good place for this. As this is very specific to the API, we should use the wiki on the API repo.

And about the changes in app behaviour, what is the extension of them?

Pretty big eh? The first step should be to review the frontend to see if all cases are covered. Then open issues for the cases not covered. I suppose that none of the 404 errors are covered.

@Miguel-Alves Miguel-Alves linked a pull request Apr 8, 2021 that will close this issue
@Miguel-Alves
Copy link
Collaborator

he API errors are Handled and the user receives a feedback about what went wrong.
It was solved through Alerts that can be improved according to the PO's preferences.

Good job! Accidentally, you did part the job of #48.

@rodmaia Thank you! I appreciate it! I noticed that it was related, but decided to do it anyway. Hope it helps and contribute somehow.

The wiki should be a good place for this. As this is very specific to the API, we should use the wiki on the API repo.

Ok, I will send it there then.

Pretty big eh? The first step should be to review the frontend to see if all cases are covered. Then open issues for the cases not covered. I suppose that none of the 404 errors are covered.

I tried to cover the errors mentioned above. Now the user receives and alert with an information about what went wrong. How front-end is under validation, I dont think other erros beyond those can happen. But just in case, I also added a default error message to the user.

@Miguel-Alves
Copy link
Collaborator

I think that when #48 is done, this work can be improved!
But, for now, I guess #175 solves the major problem

@Miguel-Alves Miguel-Alves linked a pull request Apr 8, 2021 that will close this issue
@rodmaia
Copy link
Collaborator Author

rodmaia commented Apr 14, 2021

Hope it helps and contribute somehow.

It sure will!

The wiki should be a good place for this. As this is very specific to the API, we should use the wiki on the API repo.

Ok, I will send it there then.

Be sure to add everything to the BotFlow API wiki before closing this issue

I tried to cover the errors mentioned above. Now the user receives and alert with an information about what went wrong. How front-end is under validation, I dont think other erros beyond those can happen. But just in case, I also added a default error message to the user.

A few moments ago I tried running the code on the #152-HandleApiErrors branch while the API was down and I got an error "Unhandled Rejection (TypeError): Cannot read property 'status' of undefined". You might want to double check everything.

@Miguel-Alves
Copy link
Collaborator

@rodmaia
Thank you for the remainder! I had fogotten to check if the API was online. But I corrected it now. So I guess this issue is solved. I also double checked the other errors and they are working fine, as expected.

About adding this table to the Botflow API Wiki, I went to the API repository, but couldnt find anything on its wiki. Actually, it doesnt exists. Do you want me to add it to the README file? Or where should I add it?

@rodmaia
Copy link
Collaborator Author

rodmaia commented May 19, 2021

Hey @Miguel-Alves! This issue seems trickier than we anticipated 😫. I tested the changes you made and they work nicely at first glance: I dropped the API and got the error pop-up. However, when you press OK the app is still available so I navigated to "add story", got a few more pop-ups then the app crashed.

image

After you fix that, we should probably handle these errors more gracefully. Either by having a new destination or by disabling all navigational elements on screen. In any case, I will open a new issue for that stuff so we can have some closure here.

As for the wiki, you can edit this page and put all the documentation there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API documentation Improvements or additions to documentation frontend
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants