Skip to main content

`mapCredentialUpdateError()`

Cloud has the newest features. Some may not be in a release yet; the newest release is Identity & Access Management 7.3.0.

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
errorunknown✅The 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
}
}

Was this page helpful?