lappis-unb / BotFlow

BotFlow - visual content manager for simple Rasa chatbots
GNU General Public License v3.0
30 stars 12 forks source link

Handle API errors on the frontend #152

Open rodmaia opened 3 years ago

rodmaia commented 3 years ago

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

Acceptance criteria

Miguel-Alves commented 3 years ago

@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 commented 3 years ago

 

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 commented 3 years ago

@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 commented 3 years ago

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 commented 3 years ago

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

rodmaia commented 3 years ago

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 commented 3 years ago

@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 commented 3 years ago

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.