Skip to main content
Back to Browser

mapCredentialUpdateError()

mapCredentialUpdateError maps a failure thrown by updateMeCredentials() onto the field that caused it, so a caller can attach the message to the right input instead of a form-level banner for everything.

Signature

mapCredentialUpdateError(error: unknown): CredentialUpdateErrorResult

Parameters

ParameterTypeRequiredDescription
errorunknownThe value thrown by updateMeCredentials.

Returns

CredentialUpdateErrorResult

PropertyTypeDescription
field'newPassword' | nullThe field to attach the error to, or null for a form-level error. 'newPassword' only for a 400 (the new value failing a server-side check); every other status, 403 included, has no single field to blame here, since this form collects no current-value field for one to attach to.
messagestring (optional)A server-supplied message, already human-readable. Shown as-is when present.
messageKeystringThe i18n key to fall back to when message is absent. Always set, so a caller can resolve text with a plain message ?? t(messageKey).

Usage

import { mapCredentialUpdateError, updateMeCredentials } from '@thunderid/browser'

try {
await updateMeCredentials({ baseUrl, payload: { password: newValue }, fetcher })
} catch (caughtError) {
const { field, message, messageKey } = mapCredentialUpdateError(caughtError)
const text = message ?? t(messageKey)

if (field) {
fieldErrors[field] = text // 'newPassword'
} else {
formError = text
}
}

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.