Closed hrak closed 3 years ago
This is expected behaviour, but I can see why you are confused by it.
We'll take a look at it, but are open to taking a PR if you wanted to first propose how you think it should work?
Alex
Maybe i misunderstood, but i saw it more as a way to exit the handler in any non-OK state (not 2xx or 3xx), with the ability of returning a status code and message.
This is also the idea i got from this blog post, which actually has the exact return context.status(405).fail({"status": "method not allowed"})
line as in my "Steps to reproduce" above.
What it does now is return a 500 and [object Object]
, ignores the status, and logs the message to console.
Would you be open to taking a look into this and sending in a PR @hrak?
I can take a stab at it!
This is fixed by https://github.com/openfaas/templates/pull/262
I thought we'd waited long enough given how useful this could be for other users.
If you value our work and the project then please become a GitHub Sponsor
The nodejs templates currently return a
500 Internal Server Error
in all cases (and do not output supplied result) on a call tocontext.fail()
F.e. on a return statement like this:
return context.status(405).fail({"status": "method not allowed"})
:Expected Behaviour
Current Behaviour
Possible Solution
My guess is that the arguments on this line need to be reversed
Steps to Reproduce (for bugs)
Use the following handler.js and do a GET request on it.
Context
Trying to return a 405 error on invalid method, but always getting a
500 Internal Server Error
with[object Object]
as bodyYour Environment