brave-memory-91176
03/14/2025, 3:37 PMbrief-egg-61061
03/14/2025, 3:37 PMbrief-egg-61061
03/14/2025, 3:37 PMjson { "error": { "code": 404, "debug": "SQL field \"foo\" is not a bool.", "details": {}, "id": "error_id", "message": "The resource could not be found", "reason": "User with ID 1234 does not exist.", "request": "d7ef54b1-ec15-46e6-bccb-524b82c035e6", "status": "Not Found" } }
Required fields: - error.message
Optional fields: - error.code
- The status code - error.debug
- Debug information (often not exposed to protect sensitive information) - error.details
- Further error details - error.id
- The error ID for identifying errors in application logic - error.reason
- A human-readable reason for the error - error.request
- The request ID for tracing errors across services - error.status
- The status description [Kratos API Reference](https://www.ory.sh/docs/kratos/reference/api) ## Ory Network API Error Structure For other Ory APIs (identity, events, frontend, project, workspace), the error structure is slightly different: json { "error": { "debug": "The database adapter was unable to find the element", "error": "The requested resource could not be found", "error_description": "Object with ID 12345 does not exist", "message": "Error message content", "status_code": 404 } }
Required fields: - error
(the object itself) Optional fields: - error.debug
- Debug information (usually not available unless enabled) - error.error
- The error name - error.error_description
- Further information on the nature of the error - error.message
- The error message - error.status_code
- The HTTP status code [Ory API Reference](https://www.ory.sh/docs/reference/api) While the overall structure is consistent within each API family, there are these two different formats depending on which Ory API you're using. Both formats always include the top-level error
object, but the internal structure differs slightly.brave-memory-91176
03/14/2025, 3:48 PMGenericError
type and a GenericErrorContent
type. What’s the difference?brief-egg-61061
03/14/2025, 3:48 PMbrief-egg-61061
03/14/2025, 3:48 PMGenericError
and GenericErrorContent
types. The documents only show the API response structures but don't detail the TypeScript SDK type definitions. From the error structures shown in the API documentation, I can see there are two main error formats used across Ory APIs: 1. The standard Ory JSON API error format (used in identity/frontend APIs): {
"error": {
"debug": "...",
"error": "...",
"error_description": "...",
"message": "...",
"status_code": 404
}
}
2. The generic error format (used in project/OAuth2 APIs): {
"code": 404,
"debug": "...",
"details": {},
"id": "...",
"message": "...",
"reason": "...",
"request": "...",
"status": "..."
}
It's possible that in the TypeScript SDK, GenericError
might represent the complete error response object, while GenericErrorContent
might represent the inner content of the error. However, without the actual SDK type definitions in the knowledge sources, I cannot definitively explain the difference between these two types. To get accurate information about these TypeScript types, I would recommend checking the Ory TypeScript SDK documentation or source code directly.brave-memory-91176
03/14/2025, 3:50 PM/**
* Error responses are sent when an error (e.g. unauthorized, bad request, ...) occurred.
* @export
* @interface GenericError
*/
export interface GenericError {
/**
* The status code
* @type {number}
* @memberof GenericError
*/
'code'?: number;
/**
* Debug information This field is often not exposed to protect against leaking sensitive information.
* @type {string}
* @memberof GenericError
*/
'debug'?: string;
/**
* Further error details
* @type {any}
* @memberof GenericError
*/
'details'?: any;
/**
*
* @type {GenericErrorContent}
* @memberof GenericError
*/
'error'?: GenericErrorContent;
/**
* The error ID Useful when trying to identify various errors in application logic.
* @type {string}
* @memberof GenericError
*/
'id'?: string;
/**
* Error message The error\'s message.
* @type {string}
* @memberof GenericError
*/
'message': string;
/**
* A human-readable reason for the error
* @type {string}
* @memberof GenericError
*/
'reason'?: string;
/**
* The request ID The request ID is often exposed internally in order to trace errors across service architectures. This is often a UUID.
* @type {string}
* @memberof GenericError
*/
'request'?: string;
/**
* The status description
* @type {string}
* @memberof GenericError
*/
'status'?: string;
}
/**
* Error response
* @export
* @interface GenericErrorContent
*/
export interface GenericErrorContent {
/**
* Debug contains debug information. This is usually not available and has to be enabled.
* @type {string}
* @memberof GenericErrorContent
*/
'debug'?: string;
/**
* Name is the error name.
* @type {string}
* @memberof GenericErrorContent
*/
'error'?: string;
/**
* Description contains further information on the nature of the error.
* @type {string}
* @memberof GenericErrorContent
*/
'error_description'?: string;
/**
* Message contains the error message.
* @type {string}
* @memberof GenericErrorContent
*/
'message'?: string;
/**
* Code represents the error status code (404, 403, 401, ...).
* @type {number}
* @memberof GenericErrorContent
*/
'status_code'?: number;
}
brief-egg-61061
03/14/2025, 3:50 PMbrief-egg-61061
03/14/2025, 3:50 PMGenericError
and GenericErrorContent
in the Ory TypeScript SDK: ## GenericError vs GenericErrorContent The GenericError
interface represents the top-level error response structure returned by many Ory APIs, particularly those in the project/OAuth2 family. It contains: - `code`: The HTTP status code (e.g., 404) - `debug`: Debug information (often not exposed) - `details`: Additional error details - `error`: A nested error object of type GenericErrorContent
- `id`: The error ID for tracking - `message`: The error message (this is the only required field) - `reason`: Human-readable reason for the error - `request`: Request ID for tracing (often a UUID) - `status`: Status description The GenericErrorContent
interface represents the nested error object that can appear within the error
field of GenericError
. It contains: - `debug`: Debug information (when enabled) - `error`: The error name - `error_description`: Further information about the error - `message`: The error message - `status_code`: The HTTP status code This structure matches what we discussed previously - Ory uses two slightly different error formats across its APIs. The GenericError
interface accommodates both formats by including the error
field of type GenericErrorContent
, which represents the nested error structure used in some Ory APIs like the identity/frontend APIs. This design allows the SDK to handle both error formats consistently, regardless of which Ory API you're interacting with.brave-memory-91176
03/14/2025, 3:52 PMbrief-egg-61061
03/14/2025, 3:52 PMbrief-egg-61061
03/14/2025, 3:52 PMGenericError
type as your primary error handling structure. This is because: 1. The GenericError
type is more comprehensive and encompasses both error formats used across Ory's different APIs. 2. The GenericError
interface includes the error
field which can contain a GenericErrorContent
object, allowing it to handle both the top-level error format and the nested error format. 3. The only required field in GenericError
is the message
field, which will always be present in error responses, making it a reliable property to check. When implementing error handling in your application, you might want to follow this approach: typescript try { // API call using Ory SDK } catch (err) { // Cast to GenericError if using TypeScript const error = err as GenericError; // Always available console.log(error.message); // Check for nested error content if (error.error) { console.log(error.error.error_description); } // Other optional fields if (error.reason) { console.log(error.reason); } }
For UI error handling specifically, Ory Kratos provides different levels of errors (request level, method level, and field level) as mentioned in the [Integration basics documentation](https://www.ory.sh/docs/kratos/bring-your-own-ui/custom-ui-basic-integration#error-handling). For these UI-specific errors, you'll need to handle them according to their specific structure as shown in that documentation.