Table of Contents

Class Problem

Namespace
Shift.Common
Assembly
Shift.Common.dll

Represents a machine-readable format for specifying errors in HTTP API responses

public class Problem
Inheritance
Problem
Inherited Members
Extension Methods

Remarks

Based on RFC 7807 - Problem Details for HTTP APIs. This is needed so we can use the same exception objects across all .NET versions throughout the codebase.

Constructors

Problem()

public Problem()

Problem(int)

public Problem(int statusCode)

Parameters

statusCode int

Problem(int, string)

public Problem(int statusCode, string detail)

Parameters

statusCode int
detail string

Properties

Detail

A human-readable explanation specific to this occurrence of the problem

public string Detail { get; set; }

Property Value

string

Extensions

Additional properties that provide more information about the problem

public Dictionary<string, object> Extensions { get; set; }

Property Value

Dictionary<string, object>

Instance

A URI reference that identifies the specific occurrence of the problem

public string Instance { get; set; }

Property Value

string

Status

The HTTP status code generated by the origin server

public int? Status { get; set; }

Property Value

int?

Title

A short, human-readable summary of the problem type

public string Title { get; set; }

Property Value

string

Type

A URI reference that identifies the problem type

public string Type { get; set; }

Property Value

string

Methods

Deserialize(string)

Creates a Problem from a JSON string

public static Problem Deserialize(string json)

Parameters

json string

Returns

Problem

GetDefaultTitle(int)

Returns the recommended reason phrase for a status code

public string GetDefaultTitle(int code)

Parameters

code int

Returns

string

IsRegisteredHttpStatusCode(int)

Returns true if the specified integer value represents a registered HTTP status code

public static bool IsRegisteredHttpStatusCode(int code)

Parameters

code int

The integer value to check. Valid HTTP status codes range from 100 to 599.

Returns

bool

true if the specified code is a registered HTTP status code; otherwise, false.

Examples

// Check if 200 is a valid status code
bool isValid = IsRegisteredHttpStatusCode(200);  // Returns true (OK)

// Check if 404 is a valid status code
bool isNotFound = IsRegisteredHttpStatusCode(404);  // Returns true (Not Found)

// Check if 999 is a valid status code
bool isInvalid = IsRegisteredHttpStatusCode(999);  // Returns false (not registered)

Remarks

HTTP status codes are three-digit numbers grouped into five classes:

  • 1xx (100-199): Informational responses
  • 2xx (200-299): Successful responses
  • 3xx (300-399): Redirection messages
  • 4xx (400-499): Client error responses
  • 5xx (500-599): Server error responses This method validates against the official IANA HTTP Status Code Registry and common status codes defined in various RFCs including RFC 7231, RFC 7232, RFC 7233, RFC 7235, RFC 7538, RFC 7540, RFC 7725, RFC 7694, and RFC 8297.
See Also

Serialize()

Converts a Problem to a JSON string

public string Serialize()

Returns

string