Closed atlas-wheatear closed 2 years ago
Hey @emoulsdale thanks for your interest in OpenFaaS
Can you confirm what the Content-Type is being returned by your API?
Show us the output of:
curl -i http://127.0.0.1:8080/function/name
FYI, your example doesn't return JSON or a proper content-type header, so I'm not sure why you're expecting it to do so?
Have a look at "Custom Response Headers" => https://github.com/openfaas/python-flask-template#custom-response-headers
Alex
/add label: support, question, python, templates
Seems like your function's content type was not set to JSON :)
def handle(event, context):
return {
"statusCode": 200,
"body": {"message": "Hello from OpenFaaS!"},
"headers": {
"Content-Type": "application/json"
}
}
I'll get this closed.
Bear in mind that it costs us money to answer every support question like this.
If you're using OpenFaaS, consider becoming a sponsor to OpenFaaS on a set monthly amount or some custom amount that you feel represents the value of the work we do better.
Alex
/add label: invalid
Btw, don't worry about the invalid label, it's just to help us track real issues and breakage vs user support.
You can meet us every week on Wednesdays https://docs.openfaas.com/community/
I also took the opportunity to improve the docs for the template that you're using to add the JSON example:
My actions before raising this issue
Why do you need this?
I really like the debugging UI, and would very much appreciate if I could view error JSON bodies without having to repeat the request in an external API debugger like cURL or Postman.
Expected Behaviour
The JSON body provided for the error is stringified and printed in the response-textarea.
Current Behaviour
The string
[object Object]
is printed beneath a newline. This is usually what you get when you coerce a JS object to a string.Are you a GitHub Sponsor (Yes/No?)
Check at: https://github.com/sponsors/openfaas
List All Possible Solutions and Workarounds
Modify this line here to check the type of the data from the error, and JSONify if it's an object - it currently assumes its always a string: https://github.com/openfaas/faas/blob/52d0165c3f22b5d1c269dd6e43e6e6bda6559936/gateway/assets/script/bootstrap.js#L205
An example of how to do this exists in the code a few lines above: https://github.com/openfaas/faas/blob/52d0165c3f22b5d1c269dd6e43e6e6bda6559936/gateway/assets/script/bootstrap.js#L190
Which Solution Do You Recommend?
I only suggested one solution - this is the one I recommend.
Steps to Reproduce (for bugs)
faas-cli publish
Context
## Your EnvironmentFaaS-CLI version ( Full output from:
faas-cli version
): 0.14.2Docker version
docker version
(e.g. Docker 17.0.05 ): Docker version 20.10.13, build a224086Are you using OpenFaaS on Kubernetes or faasd? kubernetes
Operating System and version (e.g. Linux, Windows, MacOS): MacOS Monterrey 12.6
Code example or link to GitHub repo or gist to reproduce problem: https://github.com/emoulsdale/openfaas-test
Other diagnostic information / logs from troubleshooting guide
I'd like to end by saying that I'm intending to make a PR to change this later.