Skip to content

Errors

Outlines the default error response schema, and some common error types.

Default response schema for 4xx and 5xx HTTP status codes.

ParameterTypeDescription
statusintegerThe HTTP status code
messagestringThe error message
errorsarrayThe errors

An example error response:

{
"status": 400,
"message": "Bad Request",
"errors": ["Invalid request body"]
}

Here’s an example of how to use the Error response within an API operation:

import "@common-grants/core";
import "@typespec/http";
using TypeSpec.Http;
using CommonGrants.Responses;
@summary("Get test")
@doc("Get a test model")
@get
op getTest(): Ok<TestModel> | Error;

The following error types are commonly used:

// 401 Unauthorized
// User is not authorized to access the resource
alias Unauthorized = Error & Http.UnauthorizedResponse;
// 404 Not Found
// The resource was not found
alias NotFound = Error & Http.NotFoundResponse;
// 400 Bad Request
// The request was invalid
alias BadRequest = Error & Http.BadRequestResponse;
// 403 Forbidden
// The action is forbidden
alias Forbidden = Error & Http.ForbiddenResponse;