Skip to main content

ThunderIDError

<ProductName />Error is the structured error class thrown by the ThunderID Nuxt SDK. It extends Error and carries a typed ErrorCode, an optional HTTP status code, an optional cause, and optional context metadata.

Import​

import { ThunderIDError, ErrorCode } from '@thunderid/nuxt/errors'

Class Definition​

class ThunderIDError extends Error {
readonly code: ErrorCode
readonly statusCode?: number
readonly cause?: unknown
readonly context?: Record<string, unknown>

constructor(
message: string,
code: ErrorCode,
opts?: {
cause?: unknown
context?: Record<string, unknown>
statusCode?: number
}
)
}

Usage​

Catching SDK Errors​

server/api/data.get.ts
import { ThunderIDError, ErrorCode } from '@thunderid/nuxt/errors'
import { getValidAccessToken } from '@thunderid/nuxt/server'

export default defineEventHandler(async (event) => {
try {
const token = await getValidAccessToken(event)
return await $fetch('/api/resource', {
headers: { Authorization: `Bearer ${token}` },
})
} catch (err) {
if (err instanceof ThunderIDError) {
if (err.code === ErrorCode.SessionExpired) {
throw createError({ statusCode: 401, statusMessage: 'Session expired' })
}
if (err.code === ErrorCode.TokenRefreshFailed) {
throw createError({ statusCode: 401, statusMessage: 'Could not refresh token' })
}
}
throw err
}
})

Properties​

PropertyTypeDescription
codeErrorCodeA typed error code identifying the failure
statusCodenumber | undefinedHTTP status code associated with the error, if applicable
causeunknownThe underlying error that caused this error, if any
contextRecord<string, unknown> | undefinedAdditional key-value metadata about the error
messagestringHuman-readable error description

ErrorCode Values​

Configuration​

CodeDescription
ConfigMissingBaseUrlbaseUrl was not provided in module configuration
ConfigMissingClientIdclientId was not provided in module configuration
ConfigMissingSecretclientSecret was not provided in module configuration

OAuth / Token​

CodeDescription
OAuthCallbackErrorThe OAuth provider returned an error during the callback
OAuthStateInvalidThe OAuth state parameter did not match the expected value
TokenExchangeFailedExchanging the authorization code for tokens failed
TokenRefreshFailedRefreshing the access token using the refresh token failed

Session​

CodeDescription
SessionExpiredThe session has passed its expiry time
SessionInvalidThe session cookie exists but cannot be verified
SessionMissingNo session cookie was found on the request
TempSessionInvalidThe temporary session used during the OAuth flow is invalid

Security​

CodeDescription
OpenRedirectBlockedA redirect URL was rejected because it points to an external origin

Organization​

CodeDescription
OrganizationCreateFailedCreating a sub-organization failed
OrganizationSwitchFailedSwitching the active organization failed

User Profile​

CodeDescription
UserProfileFetchFailedFetching the user's profile failed
UserProfileUpdateFailedUpdating the user's profile failed

Explore with AI

ThunderID LogoThunderID Logo

Product

DocsAPIsSDKs
© Copyright Linux Foundation Europe.For web site terms of use, trademark policy and other project policies please see https://linuxfoundation.eu/en/policies.