miLibris / flask-rest-jsonapi

Flask extension to build REST APIs around JSONAPI 1.0 specification.
http://flask-rest-jsonapi.readthedocs.io
MIT License
598 stars 153 forks source link

need to make sure JsonApiException().status is integer #205

Open qweasdzxcpkh opened 3 years ago

qweasdzxcpkh commented 3 years ago

Hi, i am using fastapi to deploy my backend, and using this repo to help my api code create. i found a problem when fastapi work with this repo, fastapi will split the Response().status with ' ', like:

status_code_string, _ = status.split(" ", 1)

then i watch the source code with flask, it will make confuse with '500' and 500. the Response().status setter look like this:

class BaseResponse(object):
    @property
    def status_code(self):
        """The HTTP status code as a number."""
        return self._status_code

    @status_code.setter
    def status_code(self, code):
        self._status_code = code
        try:
            self._status = "%d %s" % (code, HTTP_STATUS_CODES[code].upper())
        except KeyError:
            self._status = "%d UNKNOWN" % code

    @property
    def status(self):
        """The HTTP status code as a string."""
        return self._status

    @status.setter
    def status(self, value):
        try:
            self._status = to_native(value)
        except AttributeError:
            raise TypeError("Invalid status argument")

        try:
            self._status_code = int(self._status.split(None, 1)[0])
        except ValueError:
            self._status_code = 0
            self._status = "0 %s" % self._status
        except IndexError:
            raise ValueError("Empty status argument")