mirror of
https://github.com/Athou/commafeed.git
synced 2026-09-24 13:05:38 +00:00
Translate login authentication errors
This commit is contained in:
@@ -136,6 +136,15 @@ export const errorToStrings = (err: unknown) => {
|
||||
return strings
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform a login error into messages that can be displayed to the user.
|
||||
* Authentication failures use a client-provided message so it can be translated.
|
||||
*/
|
||||
export const loginErrorToStrings = (err: unknown, authenticationErrorMessage: string) => {
|
||||
if (isAuthenticationError(err)) return [authenticationErrorMessage]
|
||||
return errorToStrings(err)
|
||||
}
|
||||
|
||||
function isMessageError(err: AxiosError): err is AxiosError<{ message: string }> {
|
||||
return !!err.response && !!err.response.data && typeof err.response.data === "object" && "message" in err.response.data
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user