Skip to main content

Errors

The SDK uses a hierarchy of typed error classes. Catch specific classes to handle different failure modes distinctly.

Error Hierarchy

Error
└── ThunderIDError
├── ThunderIDAPIError
└── ThunderIDRuntimeError
ThunderIDAuthException (separate — thrown by auth flow internals)

ThunderIDError

Base class for all SDK errors. Extends native Error.

import { ThunderIDError } from '@thunderid/javascript'

try {
await client.initialize(config)
} catch (err) {
if (err instanceof ThunderIDError) {
console.error(err.code, err.origin, err.message)
}
}

Constructor

new ThunderIDError(message: string, code: string, origin: string)
ParameterTypeDescription
messagestringHuman-readable error description
codestringMachine-readable error code (e.g., 'JS-AUTH_CORE-RAT1-NF01')
originstringThe function or component that originated the error

Properties

PropertyTypeDescription
messagestringHuman-readable description
codestringMachine-readable error code
originstringOriginating function name

ThunderIDAPIError

Thrown when the ThunderID REST API returns an error response (4xx or 5xx).

import { ThunderIDAPIError } from '@thunderid/javascript'

try {
await getOrganization({ baseUrl, organizationId: 'bad-id', ... })
} catch (err) {
if (err instanceof ThunderIDAPIError) {
console.error(err.statusCode, err.statusText)
}
}

Constructor

new ThunderIDAPIError(
message: string,
code: string,
origin: string,
statusCode?: number,
statusText?: string,
prefix?: string,
)

Properties (extends ThunderIDError)

PropertyTypeDescription
statusCodenumberHTTP status code of the API response
statusTextstringHTTP status text (e.g., 'Not Found', 'Unauthorized')

ThunderIDRuntimeError

Thrown when an error occurs during SDK runtime operations unrelated to the API (e.g., storage failures, configuration errors).

import { ThunderIDRuntimeError } from '@thunderid/javascript'

try {
client.clearSession()
} catch (err) {
if (err instanceof ThunderIDRuntimeError) {
console.error(err.details)
}
}

Constructor

new ThunderIDRuntimeError(
message: string,
code: string,
origin: string,
details?: unknown,
)

Properties (extends ThunderIDError)

PropertyTypeDescription
detailsunknownAdditional context about the error (original exception, state dump, etc.)

ThunderIDAuthException

Thrown by the core authentication flow methods within ThunderIDJavaScriptClient (e.g., getSignInUrl(), requestAccessToken(), getSignOutUrl()). Not a subclass of ThunderIDError.

import { ThunderIDAuthException } from '@thunderid/javascript'

try {
await client.signIn()
} catch (err) {
if (err instanceof ThunderIDAuthException) {
console.error('Auth failed:', err.message)
}
}

Error Codes

Auth exception codes follow the pattern JS-AUTH_CORE-<OPERATION>-<TYPE><INDEX>:

SuffixMeaning
-NF01Not found (missing endpoint or parameter)
-NE02Network error (fetch failed)
-HE03HTTP error (non-2xx response)
-IV02Invalid (resolution or parsing failure)

Catching All SDK Errors

import {
ThunderIDError,
ThunderIDAPIError,
ThunderIDRuntimeError,
ThunderIDAuthException,
} from '@thunderid/javascript'

try {
await client.signIn()
} catch (err) {
if (err instanceof ThunderIDAPIError) {
// Handle API-level errors (HTTP 4xx/5xx from ThunderID)
console.error(`API error ${err.statusCode}: ${err.message}`)
} else if (err instanceof ThunderIDAuthException) {
// Handle auth flow errors (PKCE, token exchange, endpoint resolution)
console.error(`Auth error [${err.message}]`)
} else if (err instanceof ThunderIDRuntimeError) {
// Handle runtime/internal errors
console.error(`Runtime error: ${err.message}`, err.details)
} else if (err instanceof ThunderIDError) {
// Catch-all for any other SDK error
console.error(`SDK error [${err.code}]: ${err.message}`)
} else {
throw err // Re-throw unexpected errors
}
}
ThunderID LogoThunderID Logo

Product

DocsAPIsSDKs
© WSO2 LLC. All rights reserved.Privacy PolicyCookie Policy