Skip to content

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

@alee

Description

@alee

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions