consider preserving http status codes in DataCiteError and set them in the factory method
Is your feature request related to a problem? Please describe.
Currently the http error code is used to determine which specific DataCiteError subtype to return from the DataCiteError.factory method but it isn't preserved alongside the DataCiteError. It would be useful to keep the error code around so our backend can signal an appropriate http status code back to the user instead of maintaining the reverse mapping of http status code to DataCiteError exception class.
Describe the solution you'd like
Add a property to the DataCiteError class to store the http status code, e.g., DataCiteError.status_code and set it in the factory method that creates the specific DataCiteError subtype.
@staticmethod
def factory(err_code, *args):
"""Create exceptions through a Factory based on the HTTP error code."""
if err_code == 204:
return DataCiteNoContentError(*args, http_status_code=err_code)
elif err_code == 400:
return DataCiteBadRequestError(*args, status_code=err_code)
elif err_code == 401:
return DataCiteUnauthorizedError(*args, status_code=err_code)
...
Describe alternatives you've considered
We could also maintain a reverse mapping of DataCiteError types to status codes to map between the type of the exception and the status code that generated it.
Hi Allen! Does it happen to be the 422 error code? https://github.com/inveniosoftware/datacite/issues/89
I think we should be able to get this fixed in the release we'll do in August.