Unlike Djoser docs, our API docs do not give any information on Errors.
In order to access the error messages properly on the front-end we need a consistent way of sending the error messages.
This is how Djoser seems to handle it:
/*
An error can be global or field-specific.
If an error is global:
The status code is 401 || 403 || 404 || 500.
The error message is a string or an array of strings.
The message(s) is/are located in error.response.data.detail.
If an error is field-specific:
The status code is 400.
The error message is an object with field names as keys, and the values are arrays of strings.
The message(s) is/are located in the array of strings in error.response.data[field_name].
*/
This means that, on the front-end, I read the status code in error.response.status, and then, based on the error code, I will read the error message at the proper location and using the proper variables specified in the API docs.
Without proper documentation, I waste a lot of time figuring out how to handle the errors on the front-end.
Solution
First, we preferably need to return errors in one single coherent format (we should not return error messages in a different structure for api/ (our custom routes) than it is being returned in auth/ (djoser), so we either reproduce the same structure as how djoser handles errors, or we override djoser's) <- #221
Blocking #219
Problem
Unlike Djoser docs, our API docs do not give any information on Errors. In order to access the error messages properly on the front-end we need a consistent way of sending the error messages.
This is how Djoser seems to handle it:
This means that, on the front-end, I read the status code in
error.response.status
, and then, based on the error code, I will read the error message at the proper location and using the proper variables specified in the API docs.Without proper documentation, I waste a lot of time figuring out how to handle the errors on the front-end.
Solution
api/
(our custom routes) than it is being returned inauth/
(djoser), so we either reproduce the same structure as how djoser handles errors, or we override djoser's) <- #221