Skip to main content

Errors

Endpoints can throw errors on failure. An endpoint can have multiple errors. Errors have the following properties:

  • body: a name
  • status code: a server response to a browser’s request (optional)
  • type(s): information about the error that the client can expect (optional)

Example of using errors

The getMovie endpoint below has two errors that can throw: NotFoundError and UnauthorizedError.

services:
http:
MoviesService:
auth: false
base-path: /movies
endpoints:
getMovie:
method: GET
path: /{movieId}
path-parameters:
movieId: MovieId
response:
ok: Movie
failed:
errors:
- NotFoundError
- UnauthorizedError
errors:
NotFoundError:
http:
statusCode: 404
type:
properties:
id: MovieId
UnauthorizedError:
http:
statusCode: 401
type:
properties:
message: string

Let's say that a client hits the getMovie endpoint looking for Iron Man 5. That movie doesn't exist in IMDb, so the server would throw a NotFoundError. The response would be:

{
"_error": "NotFoundError",
"_errorInstanceId": "67d92c10-b094-49b2-8ea4-0b84013ad1bc",
"MovieId": "Iron Man 5"
}

By providing the MovieId the frontend can now display a string to the user: "No results found for "Iron Man 5".

Forward compatiblility

Errors are forward compatibile; you can add errors as you go without breaking clients.

Error instance ids

When an error is encountered, an errorInstanceId is generated automatically and can be logged, making debugging easier.