restless
restless copied to clipboard
detail method should return status code 404 on None
Rather than return a status code of 200, the detail method should return a status code of 404 if nothing is returned.
I'm running into the same problem. I can't seem to find the right way to return a simple error response - it ends up trying to re-serialize the error dict as if it was my resource type. What's the recommended way to return arbitrary HTTP responses from a view handler?
Update: here's the code in resources.py where I run into the problem:
data = view_method(*args, **kwargs)
serialized = self.serialize(method, endpoint, data)
When the response is an error (e.g. 404) the view method returns a complete response, but in the line it tries to serialize it as if it's resource data.
I'll step out of this thread because I figured out my issues, how to return a 404 - I needed to raise a NotFound() exception instead of trying to return a response.