-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix error handler type hint, use flask defined route response types #39
Conversation
def success(cls, data: JSONType) -> FlaskResponseType: | ||
return data, HTTPStatus.OK | ||
def success(cls, data: JSONType) -> ResponseReturnValue: | ||
return json.dumps(data), HTTPStatus.OK |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does change output when using curl
. I'm not sure if this will cause issues when we implement the frontend.
Steps to reproduce:
- Generate id token. See Write a script to generate a sample id_token #31 for details
- Set the ID token to a variable
token
in shell - Run the backend and run this command
curl -X GET -H "Authorization: Bearer $token" -H 'Content-Type: application/json' localhost:3001/me
Output before MR:
{
"name": "test",
"email": "[email protected]",
"database": null
}
Output after MR:
"{\"name\": \"test\", \"email\": \"[email protected]\", \"database\": null}"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nevermind. I did a test and this isn't a problem for browsers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did this change the headers in the response? i'm guessing if the headers don't say its a json curl might default to displaying as a string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it doesn't change the headers. My guess is that json.dumps()
changes the formatting to include \
After Changes:
Internal server errorgcarvellas@razer-blade-15:~$ curl -v -X GET localhost:3001/health
Note: Unnecessary use of -X or --request, GET is already inferred.
* processing: localhost:3001/health
* Trying [::1]:3001...
* Connected to localhost (::1) port 3001
> GET /health HTTP/1.1
> Host: localhost:3001
> User-Agent: curl/8.2.1
> Accept: */*
>
< HTTP/1.1 200 OK
< Server: gunicorn
< Date: Thu, 14 Sep 2023 18:57:58 GMT
< Connection: keep-alive
< Content-Type: application/json
< Content-Length: 9
< Access-Control-Allow-Origin: *
<
"\"ok\""
Before Changes:
gcarvellas@razer-blade-15:~$ curl -v -X GET localhost:3001/health
Note: Unnecessary use of -X or --request, GET is already inferred.
* processing: localhost:3001/health
* Trying [::1]:3001...
* Connected to localhost (::1) port 3001
> GET /health HTTP/1.1
> Host: localhost:3001
> User-Agent: curl/8.2.1
> Accept: */*
>
< HTTP/1.1 200 OK
< Server: gunicorn
< Date: Thu, 14 Sep 2023 18:58:40 GMT
< Connection: keep-alive
< Content-Type: application/json
< Content-Length: 5
< Access-Control-Allow-Origin: *
<
"ok"
closing this since we're not using Flask anymore |
FlaskResponseType
with theResponseReturnValue
type from flask.typing