Skip to content

5. API reference

Stratis Dermanoutsos edited this page Jul 28, 2025 · 11 revisions

1. Abstractions

IRestException

Used to enforce the implementation of a default message by all different instances of RestException.

public interface IRestException
{
    static abstract string DefaultMessage { get; }
}

Members:

  • DefaultMessage: (static, abstract) Used when the user does not provide a message when throwing an exception. For each RestException inheritor class, a generic description of the HTTP error's reference has been provided.

RestException

public abstract class RestException(string message, Dictionary<string, object?>? extensions) : Exception(message)
{
    public abstract string Title { get; }
    public abstract HttpStatusCode StatusCode { get; }
    public Dictionary<string, object?> Extensions { get; }
    public string TypeSuffix { get; }
}

Members:

  • Title: (abstract) The title of the HTTP error. This defaults to the error's name. E.g. "Not Found" when a 404 is thrown.
  • StatusCode: (abstract) The status of the HTTP error. For more details on this, visit wikipedia.
  • Extensions: A dictionary used to add custom properties to the resulting ProblemDetails response.
  • TypeSuffix: Returns the concatenated string that consist of StatusCode and Title joined by "-" in kebab case.

References:

  1. HttpStatusCode

IRestExceptionProblemDetailsBuilder

Interface used for implementing custom ProblemDetails builders.

public interface IRestExceptionProblemDetailsBuilder
{
    ProblemDetails Build(HttpContext httpContext, RestException restException);
}

Members:

  • Build: It consumes an HttpContext and a RestException instance to produce the end result.

References:

  1. ProblemDetails
  2. HttpContext
  3. RestException

DefaultRestExceptionProblemDetailsBuilder

public sealed class DefaultRestExceptionProblemDetailsBuilder : IRestExceptionProblemDetailsBuilder
{
    // ...
}

The default implementation used by the package itself. Can be used to more easily define a custom builder.

2. Implemented exceptions

Grouped by their status code's first digit and sorted

  • 4xx (client error)
    • (400) BadRequestRestException
    • (401) UnauthorizedRestException
    • (402) PaymentRequiredRestException
    • (403) ForbiddenRestException
    • (404) NotFoundRestException
    • (405) MethodNotAllowedRestException
    • (406) NotAcceptableRestException
    • (407) ProxyAuthenticationRequiredRestException
    • (408) RequestTimeoutRestException
    • (409) ConflictRestException
    • (410) GoneRestException
    • (411) LengthRequiredRestException
    • (412) PreconditionFailedRestException
    • (413) ContentTooLargeRestException
    • (414) UriTooLongRestException
    • (415) UnsupportedMediaTypeRestException
    • (416) RangeNotSatisfiableRestException
    • (417) ExpectationFailedRestException
    • (421) MisdirectedRequestRestException
    • (422) UnprocessableContentRestException
    • (423) LockedRestException
    • (424) FailedDependencyRestException
    • (426) UpgradeRequiredRestException
    • (428) PreconditionRequiredRestException
    • (429) TooManyRequestsRestException
    • (431) RequestHeaderFieldsTooLargeRestException
    • (451) UnavailableForLegalReasonsRestException
  • 5xx (server error)
    • (500) InternalServerErrorRestException
    • (501) NotImplementedRestException
    • (502) BadGatewayRestException
    • (503) ServiceUnavailableRestException
    • (504) GatewayTimeoutRestException
    • (505) HttpVersionNotSupportedRestException
    • (506) VariantAlsoNegotiatesRestException
    • (507) InsufficientStorageRestException
    • (508) LoopDetectedRestException
    • (510) NotExtendedRestException
    • (511) NetworkAuthenticationRequiredRestException
Clone this wiki locally