Considerations for error pathways for endpoints #55
Replies: 6 comments 13 replies
-
Our open api generator tool, redocly, recommends that every endpoint return a 4xx series code. This makes sense. In practice, client request errors can derive from parts of the http request other than the url. MDN mentions "malformed request syntax, invalid request message framing, or deceptive request routing" as possible sources of 400 errors. Consequently, even endpoints that do not have dynamic path or query parameters can still have client errors. To account for these errors, we should add
Implementation of this response should already be handled by Nest JS. 400 codes for bad requests are well-defined and Nest JS is generally designed to handle common cases like this. |
Beta Was this translation helpful? Give feedback.
-
Routes that do accept path parameters may receive requests that are valid but no resource exists at that endpoint. These endpoints fall into two categories- those that make requests to the database and those that redirect to tilesets. The database routes stay within the application and the application has direct control over the response. These endpoints are:
The api should return a 404 for these routes. In Open API, we should have a response of structure:
The tileset routes redirect to our S3 bucket provider. When the targeted endpoint resource does not exist, the bucket returns a 403 Access Denied with the following XML response.
Because this does not follow the Error schema, the schema should be built using a new generic with xml representations
This applies to the following tileset routes:
|
Beta Was this translation helpful? Give feedback.
-
@bmarchena @dhochbaum-dcp @horatiorosa @TylerMatteo Any thoughts on either the existing comments or things that haven't been considered yet? |
Beta Was this translation helpful? Give feedback.
-
joi.dev reminds me of validation we use in EDDE called YUP. Would that potentially be useful here? |
Beta Was this translation helpful? Give feedback.
-
@TangoYankee This is really great, thank you for documenting your deep dive on the topic. I'll try to organize my thoughts as best as I can below: 400 responsesI'm sold on buying into Redocly rule of all requests having a 4xx response type, even for requests where there are no path parameters. I'm thinking routes with no path params would just have a 400 response type. For routes with with path params, do you think we should have 404 and 400 or just 404? It seems to be that technically we should - 400 if the request is invalid and 404 if it is valid but we just couldn't find a record for the supplied params. Another thought I had is how do 5xx responses fit into this? This is maybe something we can table for now but I'm a little surprised redoc's linter requires 4xx but not 5xx. After all, if one of our Shape of (non-XML) error responsesI think you have the right idea already - I think we should lean into the built in HTTP Exceptions supplied by Nest and design our OpenAPI schemas accordingly. XML errorsI'm fine with implementing the XML error that comes back from DO like you're doing above, but this is something we should revisit. I'm not sure that we're actually "responsible" for describing the error that comes back from DO. I think that error is actually seen as not coming from our API because it's the result after a redirect. As far as our API is concerned:
|
Beta Was this translation helpful? Give feedback.
-
@TylerMatteo I experimented with how to make the exceptions reusable. See the error folder to see an example InvalidRequestParameterException and its use in the tax lot service. |
Beta Was this translation helpful? Give feedback.
-
Description
The Open API documentation covers the happy paths for the endpoints. We should start to consider how each endpoint may find itself in an error state. From there we can first document in OpenAPI how the application will behave in these errors states. Then, we implement code to handle these error states.
Discussion strategy
This top-level comment will capture each endpoint and the error paths we wish to capture. Ideas can be added through comments and discussed in replies. As we reach a consensus, this top-level comment will be updated to reflect this consensus. Once we feel we have settled on a list of error states to cover, we can break the work into separate tickets.
Consensus
Type Validation
There hasn't been a strong preference shown for a validator library, other than wanting to coalesce around a common library. But because drizzle provides a drizzle-zod library and zod appears to be a mature library in this space, we should leverage zod here.
Endpoints
boroughs
/boroughs
Land uses
/land-uses
Tax lots
tax-lots/<bbl>
tax-lots/<bbl>/geojson
tax-lots/<bbl>/zoning-districts
findFirst
. If there is a result, it can proceed to find the zoning districts for that tax lottax-lots/<bbl>/zoning-districts/classes
findFirst
. If there is a result, it can proceed to find the zoning district classes for that tax lottax-lots/<z>/<x>/<y>.pbf
Zoning districts
zoning-districts/<uuid>
zoning-districts/<uuid>/classes
findFirst
. If there is a result, it can proceed to find the classes for the zoning districtzoning-districts/<z>/<x>/<y>.pbf
Zoning district classes
zoning-district-classes
zoning-district-classes/category-colors
zoning-district-classes/<id>
Schemas
Messages
The messages returned from the api for each type of error (there may be different messages for each status code, depending on the cause)
Beta Was this translation helpful? Give feedback.
All reactions