Skip to content

Conversation

RobertLucian
Copy link
Member

@RobertLucian RobertLucian commented Jul 8, 2020

Closes #1208.

It appears that with the FastAPI web framework, throwing exceptions in the middleware is not the intended way of handling errors. It is assumed that any exceptions occurring in the middleware are gracefully handled, meaning that instead of throwing exceptions, responses are expected to be returned instead. It is therefore assumed that any exceptions occurring in the middleware are just implementation errors and thus returning the 500 status code is acceptable (aka what we've been returning so far).

The only place where the @app.exception_handler handlers are used is right after the middleware once an API route has already been taken (e.g. predict or summary). In order for those handlers to work, an API route handler would have to throw an exception that would match one of the handlers' exceptions.

A couple of resources that helped me with this are the following:


checklist:

  • run make test and make lint
  • test manually (i.e. build/push all images, restart operator, and re-deploy APIs)
  • update docs and add any new files to summary.md (view in gitbook after merging)

@RobertLucian RobertLucian added the bug Something isn't working label Jul 8, 2020
@RobertLucian RobertLucian requested a review from vishalbollu July 11, 2020 12:26
@RobertLucian RobertLucian requested a review from vishalbollu July 14, 2020 23:01
The `payload` parameter is parsed according to the `Content-Type` header in the request. For `Content-Type: application/json`, `payload` will be the parsed JSON body. For `Content-Type: multipart/form` or `Content-Type: application/x-www-form-urlencoded`, `payload` will be `starlette.datastructures.FormData` (key-value pairs where the value is a `string` for form data, or `starlette.datastructures.UploadFile` for file uploads, see [Starlette's documentation](https://www.starlette.io/requests/#request-files)). For all other `Content-Type` values, `payload` will be the raw `bytes` of the request body.
Your API can accept requests with different types of payloads such as `JSON`-parseable, `bytes` or `starlette.datastructures.FormData` data. Navigate to the [API requests](#api-requests) section to learn about how headers can be used to change the type of `payload` that is passed into your `predict` function.

Your API can be configured to respond with different types of payload such as `JSON`-parseable, `string`, and `bytes` objects. Navigate to the [API responses](#api-responses) section to learn about how your API can respond with different response codes and content-types.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your predictor can return different types of objects such as JSON-parseable, string, and bytes objects. Navigate to the API responses section to learn about how to configure your predictor to respond with different response codes and content-types.

@RobertLucian RobertLucian removed the request for review from deliahu July 17, 2020 12:24
@RobertLucian RobertLucian merged commit 0ac92c7 into master Jul 17, 2020
@RobertLucian RobertLucian deleted the fix/request-behavior branch July 17, 2020 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bad request is returning 500 status code instead of 400
2 participants