Skip to content

error codes for dropshot-provided errors need work #41

Open
@davepacheco

Description

@davepacheco

As it says in error.rs, we envision that errors from an API typically have a string code (separate from the HTTP status code):

* `HttpError` represents an error generated as part of handling an API
* request. When these bubble up to the top of the request handling stack
* (which is most of the time that they're generated), these are turned into an
* HTTP response, which includes:
*
* * a status code, which is likely either 400-level (indicating a client
* error, like bad input) or 500-level (indicating a server error).
* * a structured (JSON) body, which includes:
* * a string error code, which identifies the underlying error condition
* so that clients can potentially make programmatic decisions based on
* the error type
* * a string error message, which is the human-readable summary of the
* issue, intended to make sense for API users (i.e., not API server
* developers)
* * optionally: additional metadata describing the issue. For a
* validation error, this could include information about which
* parameter was invalid and why. This should conform to a schema
* associated with the error code.

I've generally assumed that the namespace of these codes needs to be under the control of the Dropshot consumer, since they will likely be defining most of the codes for their own application-specific conditions. However, Dropshot currently generates a bunch of different errors of its own (e.g., when a request arrives for a path that has no handler associated with it). What code should it use?

I'm thinking out loud through a bunch of options here:

  1. Have Dropshot define a set of codes for itself and let consumers use whatever codes they want, too. This kind of sucks. It's hard to expand Dropshot's set later since we might stomp on a code that consumers are already using. We could use a prefix to carve out part of the namespace, but this is part of the consumer's public API -- that's ugly. Plus, it's hard for Dropshot to make judgments about what error cases a consumer's client wants to distinguish.
  2. Let the consumer define the entire namespace and allow consumers to define the codes that Dropshot will use for its own errors. Maybe the caller provides a function that maps HTTP status codes to Strings (or something that we can turn into a String). Or maybe Dropshot defines an enum for the conditions it needs to generate codes for and consumers provide a function that maps from that. We could even provide a default implementation that would hopefully be suitable for most consumers. This gives us most of the benefits of (1) but without the expansion problem -- if we expand it, if the consumer uses a match, they'll get a compile error that forces them to decide how to map the new condition.
  3. Have Dropshot own the entire namespace: create a set of codes like ObjectNotFound, BadArgs, etc. and require that consumers use these. This might actually be nice because many consumers will wind up using a lot of the same codes, but it seems like a non-starter that consumers can't extend this.

The behavior today is that the code is optional and Dropshot generally provides None. That was basically a hack to be able to make forward progress -- it's pretty crappy for consumers and their users.

See also #39.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions