ErrorCode
Modules
Class Methods
.find
.find(key)
Finds an error code by key.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
key | Symbol | The error code key. |
Returns
See also
Example
ruby
Apiwork::ErrorCode.find(:not_found).find!
.find!(key)
Finds an error code by key.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
key | Symbol | The error code key. |
Returns
See also
Example
ruby
Apiwork::ErrorCode.find!(:not_found).register
.register(key, attach_path: false, status:)
Registers a custom error code for use in API responses.
Error codes are used with raises declarations and expose_error in controllers. Built-in codes (400-504) are pre-registered.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
key | Symbol | The unique identifier for the error code. | |
attach_path | Boolean | false | Include request path in error response. |
status | Integer | The HTTP status code (must be 400-599). |
Returns
See also
Example: Register custom error code
ruby
Apiwork::ErrorCode.register :resource_locked, status: 423Example: With path attachment
ruby
Apiwork::ErrorCode.register :not_found, status: 404, attach_path: trueInstance Methods
#key
#key
The key for this error code.
Returns
Symbol
#status
#status
The status for this error code.
Returns
Integer