Class RESTError
This class standardizes the format, status codes, descriptions, and supplemental data returned by ASP.Net in the event of a failure. This class should be utilized instead of Throw(string, int, Exception?) to report issues to the API user. This class can be instantiated with any of the static factory methods.
Implements
Inherited Members
Namespace: Quantellia.WMServer.REST
Assembly: WMServer.dll
Syntax
public class RESTError : Exception, ISerializable
Properties
HTTPStatusCode
The status code of this error. Set by factory methods.
Declaration
public int HTTPStatusCode { get; }
Property Value
| Type | Description |
|---|---|
| int |
InnerException
The exception that directly caused this RESTError. The message and stack trace will be included in the log.
Declaration
public Exception? InnerException { get; set; }
Property Value
| Type | Description |
|---|---|
| Exception |
InternalMessage
Additional details on the error. This is only seen by internal logs, and never the API user.
Declaration
public string? InternalMessage { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Message
Additional details on the error. Set by factory methods and modifiable.
Declaration
public string? Message { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
StatusDescription
The status description of this error. Set by factory methods.
Declaration
public string StatusDescription { get; }
Property Value
| Type | Description |
|---|---|
| string |
ValidationData
Optional validation info to include in the response. (I.e. LLM : ["ChatGPT"] to indicate that the "LLM" field only allows the "ChatGPT" value.)
Declaration
public Dictionary<string, object> ValidationData { get; set; }
Property Value
| Type | Description |
|---|---|
| Dictionary<string, object> |
Methods
Conflict(string)
Generates a RESTError indicating that a request cannot be completed due to conflict. This should only be used when there is a conflict with public information. I.e. a conflict is appropriate when making a new organization with duplicate names.
Declaration
public static RESTError Conflict(string message)
Parameters
| Type | Name | Description |
|---|---|---|
| string | message | By default, "The requested resource does not exist.", specifies what wasn't found. |
Returns
| Type | Description |
|---|---|
| RESTError |
Forbidden(string)
Generates a RESTError indicating that the user does not have authorization.
Declaration
public static RESTError Forbidden(string message = "Access to resource is denied because user does not have Administrator privileges ")
Parameters
| Type | Name | Description |
|---|---|---|
| string | message | By default, "Access to resource is denied because user does not have Administrator privileges ", specifies that the operation is forbidden. |
Returns
| Type | Description |
|---|---|
| RESTError |
InternalServerError(string, Exception?, string?)
Generates a RESTError indicating that an internal server error occurred. Unless otherwise specified, this will send a generic message to the API user, and record details in the log.
Declaration
public static RESTError InternalServerError(string internalMessage, Exception? innerException = null, string? message = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | internalMessage | Details to include in the log. |
| Exception | innerException | An optional inner exception to include in the log. |
| string | message | An optional message to send to the client. |
Returns
| Type | Description |
|---|---|
| RESTError |
LicenseExpired(DateTime)
Generates a RESTError indicating an expired license.
Declaration
public static RESTError LicenseExpired(DateTime expiration)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | expiration |
Returns
| Type | Description |
|---|---|
| RESTError |
LicenseInactive()
Generates a RESTError indicating that the provided license has not been activated.
Declaration
public static RESTError LicenseInactive()
Returns
| Type | Description |
|---|---|
| RESTError |
LicenseInvalid()
Generates a RESTError indicating that the provided license is invalid (tampered, missing required information, etc...)
Declaration
public static RESTError LicenseInvalid()
Returns
| Type | Description |
|---|---|
| RESTError |
LicenseMissing(string)
Generates a RESTError indicating that the provided license does not exist in our system.
Declaration
public static RESTError LicenseMissing(string message = "License does not exist.")
Parameters
| Type | Name | Description |
|---|---|---|
| string | message |
Returns
| Type | Description |
|---|---|
| RESTError |
NotFound(string)
Generates a RESTError indicating that an internal server error occurred. Unless otherwise specified, this will send a generic message to the API user, and record details in the log.
Declaration
public static RESTError NotFound(string message = "The requested resource does not exist.")
Parameters
| Type | Name | Description |
|---|---|---|
| string | message | By default, "The requested resource does not exist.", specifies what wasn't found. |
Returns
| Type | Description |
|---|---|
| RESTError |
Permission(WMResource, WMOperation, string)
Generates a RESTError indicating missing permission
Declaration
public static RESTError Permission(WMBaseResouceOperation.WMResource resource, WMBaseResouceOperation.WMOperation operation = WMOperation.Get, string applicationID = "WMServer")
Parameters
| Type | Name | Description |
|---|---|---|
| WMBaseResouceOperation.WMResource | resource | The resource denied. |
| WMBaseResouceOperation.WMOperation | operation | The operation denied. |
| string | applicationID | The application this took place in. WMServerApplicationID by default. |
Returns
| Type | Description |
|---|---|
| RESTError |
Permission(string)
Generates a RESTError indicating missing permission
Declaration
public static RESTError Permission(string message = "Permission denied by organization")
Parameters
| Type | Name | Description |
|---|---|---|
| string | message |
Returns
| Type | Description |
|---|---|
| RESTError |
ToString()
Converts this RESTError to an internal log message.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string |
Overrides
Validation(string, Dictionary<string, object>?)
Generates a RESTError indicating that the request did not pass validation.
Declaration
public static RESTError Validation(string reason, Dictionary<string, object>? initialValidationData = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | reason | The reason for the validation error. |
| Dictionary<string, object> | initialValidationData | A set of fields and the data structure or values they should adhere to. |
Returns
| Type | Description |
|---|---|
| RESTError |
ValidationEnum<TEnum>(TEnum, List<TEnum>?, string)
Generates a RESTError indicating that the provided value is not among allowed Enum types. Disallowed enum types can be specified in the except list.
Declaration
public static RESTError ValidationEnum<TEnum>(TEnum value, List<TEnum>? except = null, string valueName = "member") where TEnum : struct, Enum
Parameters
| Type | Name | Description |
|---|---|---|
| TEnum | value | The enum variable |
| List<TEnum> | except | Enum values that are not supported. |
| string | valueName | The name of the variable passed as |
Returns
| Type | Description |
|---|---|
| RESTError |
Type Parameters
| Name | Description |
|---|---|
| TEnum |