restless icon indicating copy to clipboard operation
restless copied to clipboard

detail method should return status code 404 on None

Open ghost opened this issue 10 years ago • 2 comments

Rather than return a status code of 200, the detail method should return a status code of 404 if nothing is returned.

ghost avatar Nov 07 '14 20:11 ghost

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.

peplin avatar Nov 11 '14 22:11 peplin

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.

peplin avatar Nov 12 '14 14:11 peplin