inveniosoftware / inveniosoftware/datacite

consider preserving http status codes in DataCiteError and set them in the factory method

Open
#98 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
34
Forks
32
PR merge metrics
No merged PRs in 30d

Description

## 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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.