Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ const FALLBACK_ERROR_MESSAGE = "We couldn't save this credential. Try again in a
function messageForClientCredentialError(
err: unknown,
descriptor: ClientCredentialAccountDescriptor,
requiredFields: ClientCredentialAccountField[]
requiredFields: ClientCredentialAccountField[],
fallbackMessage = FALLBACK_ERROR_MESSAGE
): string {
if (isApiClientError(err) && err.code) {
// Names the fields the *selected* auth method needed, so a JWT failure
Expand All @@ -68,10 +69,10 @@ function messageForClientCredentialError(
case 'duplicate_display_name':
return 'A credential with that name already exists in this workspace.'
default:
return FALLBACK_ERROR_MESSAGE
return fallbackMessage
}
}
return FALLBACK_ERROR_MESSAGE
return fallbackMessage
}

type FieldValues = Partial<Record<ClientCredentialAccountFieldId, string>>
Expand Down Expand Up @@ -237,9 +238,12 @@ function ClientCredentialAccountModalForm({
onOpenChange(false)
} catch (err: unknown) {
setError(
onSubmitCredentials
? getErrorMessage(err, FALLBACK_ERROR_MESSAGE)
: messageForClientCredentialError(err, descriptor, required)
messageForClientCredentialError(
err,
descriptor,
required,
onSubmitCredentials ? getErrorMessage(err, FALLBACK_ERROR_MESSAGE) : undefined
)
)
logger.error(`Failed to save ${descriptor.serviceLabel} service account credential`, err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,11 @@ function TokenServiceAccountModalForm({
} catch (err: unknown) {
const code = isApiClientError(err) ? err.code : undefined
setError(
onSubmitCredentials
? getErrorMessage(err, 'Could not save this connection.')
: getTokenServiceAccountErrorMessage(descriptor, code)
getTokenServiceAccountErrorMessage(
descriptor,
code,
onSubmitCredentials ? getErrorMessage(err, 'Could not save this connection.') : undefined
)
)
logger.error(`Failed to add ${descriptor.serviceLabel} service account credential`, err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,11 +534,12 @@ export function getTokenServiceAccountDescriptor(
* given provider. Provider-specific copy is inherited from the descriptor
* (token noun, service label, and the optional `invalidCredentialsHelp`
* override) rather than hard-coded in the shared connect modal. An
* unknown/absent code falls back to a generic retry message.
* unknown/absent code uses the caller's fallback or a generic retry message.
*/
export function getTokenServiceAccountErrorMessage(
descriptor: TokenServiceAccountDescriptor,
code: string | undefined
code: string | undefined,
fallbackMessage = "We couldn't add this credential. Try again in a moment."
): string {
switch (code) {
case 'invalid_credentials':
Expand All @@ -553,6 +554,6 @@ export function getTokenServiceAccountErrorMessage(
case 'duplicate_display_name':
return 'A credential with that name already exists in this workspace.'
default:
return "We couldn't add this credential. Try again in a moment."
return fallbackMessage
}
}
Loading