I'm working on a RESTful application structured like this:
- Backend: Django with Django Rest Framework API
- Frontent: Angular 2
- UI: Bootstrap 4
When I post data from Angular to my backend REST api, DRF returns differents datas (with status code) depending on what happened. Example:
- HTTP_201_CREATED if the create post was successful
- HTTP_403_FORBIDDEN if the user doesn't have the permission
- HTTP_400_BAD_REQUEST if the sent datas are not correclty formated
- ...
(Sub question : what should be the structure of a HTTP_400_BAD_REQUEST response if you want to add customs error messages ?)
In Bootstrap V4, there are contextuals classes :
- .active
- .success
- .info
- .warning
- .danger
Can somebody suggest a elegant way (and as generic as possible) to set the bootstrap class depending on the request status with Angular 2 ? For example, if the REST api returns an error, display the error message and set the danger class to the concernent Boostrap DOM. If the REST api return success status, display a success message with the success Bootstrap class, etc...