Neuron-PHP

ProblemType : string

Standard problem type URIs for common API errors.

This enum defines standard problem type URIs that can be reused across API implementations to ensure consistency. These types follow a URI path pattern that can be resolved to documentation if needed.

Problem types are URIs that identify the type of problem. While they don't need to be resolvable, RFC 9457 encourages using URIs that can provide documentation when dereferenced.

The URIs use a relative path format (/errors/...) which allows them to be prefixed with a base URI for each application, making them both portable and customizable.

Tags
example
// Use standard problem type for validation errors
$problem = new ProblemDetails(
    type: ProblemType::VALIDATION_ERROR->value,
    title: 'Validation Failed',
    status: 400,
    detail: 'The email field is required'
);

// Or use the enum directly with type hinting
public function createProblem(ProblemType $type): ProblemDetails {
    return match($type) {
        ProblemType::VALIDATION_ERROR => new ProblemDetails(...),
        ProblemType::NOT_FOUND => new ProblemDetails(...),
        // ...
    };
}

Table of Contents

Cases

AUTHENTICATION_REQUIRED  = '/errors/authentication'
Authentication required - The request requires authentication.
BAD_REQUEST  = '/errors/bad-request'
Bad request - The request is malformed or invalid.
CONFLICT  = '/errors/conflict'
Conflict - The request conflicts with current state.
INTERNAL_ERROR  = '/errors/internal'
Internal server error - An unexpected error occurred.
METHOD_NOT_ALLOWED  = '/errors/method-not-allowed'
Method not allowed - HTTP method not supported for this endpoint.
NOT_FOUND  = '/errors/not-found'
Resource not found - The requested resource does not exist.
PAYLOAD_TOO_LARGE  = '/errors/payload-too-large'
Payload too large - Request body exceeds size limits.
PERMISSION_DENIED  = '/errors/authorization'
Permission denied - Authenticated user lacks required permissions.
RATE_LIMIT_EXCEEDED  = '/errors/rate-limit'
Rate limit exceeded - Too many requests from this client.
REQUEST_TIMEOUT  = '/errors/timeout'
Request timeout - The request took too long to process.
SERVICE_UNAVAILABLE  = '/errors/service-unavailable'
Service unavailable - The service is temporarily unavailable.
UNSUPPORTED_MEDIA_TYPE  = '/errors/unsupported-media-type'
Unsupported media type - Request content type not supported.
VALIDATION_ERROR  = '/errors/validation'
Validation error - Request data failed validation rules.

Methods

getDefaultTitle()  : string
Get the default title for this problem type.
getRecommendedStatus()  : int
Get the recommended HTTP status code for this problem type.
toProblemDetails()  : ProblemDetails
Create a ProblemDetails instance from this type.

Cases

VALIDATION_ERROR

Validation error - Request data failed validation rules.

Typically includes an 'errors' extension with field-specific messages. HTTP Status: 400 Bad Request

NOT_FOUND

Resource not found - The requested resource does not exist.

Should include details about what resource was not found. HTTP Status: 404 Not Found

AUTHENTICATION_REQUIRED

Authentication required - The request requires authentication.

User needs to authenticate before accessing the resource. HTTP Status: 401 Unauthorized

PERMISSION_DENIED

Permission denied - Authenticated user lacks required permissions.

User is authenticated but not authorized for this action. HTTP Status: 403 Forbidden

RATE_LIMIT_EXCEEDED

Rate limit exceeded - Too many requests from this client.

May include 'retry_after' extension with seconds to wait. HTTP Status: 429 Too Many Requests

SERVICE_UNAVAILABLE

Service unavailable - The service is temporarily unavailable.

May occur during maintenance or high load. HTTP Status: 503 Service Unavailable

INTERNAL_ERROR

Internal server error - An unexpected error occurred.

Should not expose internal details in production. HTTP Status: 500 Internal Server Error

BAD_REQUEST

Bad request - The request is malformed or invalid.

Generic client error when more specific type doesn't apply. HTTP Status: 400 Bad Request

CONFLICT

Conflict - The request conflicts with current state.

Often used for duplicate resources or version conflicts. HTTP Status: 409 Conflict

METHOD_NOT_ALLOWED

Method not allowed - HTTP method not supported for this endpoint.

Should include 'allowed_methods' extension. HTTP Status: 405 Method Not Allowed

UNSUPPORTED_MEDIA_TYPE

Unsupported media type - Request content type not supported.

Should include 'supported_types' extension. HTTP Status: 415 Unsupported Media Type

REQUEST_TIMEOUT

Request timeout - The request took too long to process.

HTTP Status: 408 Request Timeout

PAYLOAD_TOO_LARGE

Payload too large - Request body exceeds size limits.

May include 'max_size' extension. HTTP Status: 413 Payload Too Large

Methods

getDefaultTitle()

Get the default title for this problem type.

public getDefaultTitle() : string
Return values
string

A human-readable title

getRecommendedStatus()

Get the recommended HTTP status code for this problem type.

public getRecommendedStatus() : int
Return values
int

The HTTP status code

toProblemDetails()

Create a ProblemDetails instance from this type.

public toProblemDetails([string|null $detail = null ][, string|null $instance = null ][, array<string|int, mixed> $extensions = [] ]) : ProblemDetails
Parameters
$detail : string|null = null

Specific details about this occurrence

$instance : string|null = null

URI identifying this specific occurrence

$extensions : array<string|int, mixed> = []

Additional fields to include

Return values
ProblemDetails

        
On this page

Search results