From ec0914ae254af409da1f0b775460d5234b6484b7 Mon Sep 17 00:00:00 2001 From: André Oliveira Date: Thu, 28 Sep 2023 16:11:37 +0100 Subject: fix: login and signup error messages --- src/api/server/ServerApi.ts | 36 ++++++++++++++++++++++++------------ src/components/auth/Login.tsx | 38 +++++++++++++++++++++----------------- src/components/auth/Signup.tsx | 6 +++--- 3 files changed, 48 insertions(+), 32 deletions(-) diff --git a/src/api/server/ServerApi.ts b/src/api/server/ServerApi.ts index 7b17fcdcd..8e1d45588 100644 --- a/src/api/server/ServerApi.ts +++ b/src/api/server/ServerApi.ts @@ -62,13 +62,19 @@ export default class ServerApi { }, false, ); - if (!request.ok) { - throw new Error(request.statusText); - } - const u = await request.json(); + try { + const responseJson = await request.json(); - debug('ServerApi::login resolves', u); - return u.token; + if (!request.ok) { + throw responseJson; + } + + debug('ServerApi::login resolves', responseJson); + return responseJson.token; + } catch (error) { + debug('ServerApi::login ERROR:', error); + throw error; + } } async signup(data: any) { @@ -80,13 +86,19 @@ export default class ServerApi { }, false, ); - if (!request.ok) { - throw new Error(request.statusText); - } - const u = await request.json(); + try { + const responseJson = await request.json(); - debug('ServerApi::signup resolves', u); - return u.token; + if (!request.ok) { + throw responseJson; + } + + debug('ServerApi::signup resolves', responseJson); + return responseJson.token; + } catch (error) { + debug('ServerApi::signup ERROR:', error); + throw error; + } } async inviteUser(data: any) { diff --git a/src/components/auth/Login.tsx b/src/components/auth/Login.tsx index cf7abe654..9bad731c8 100644 --- a/src/components/auth/Login.tsx +++ b/src/components/auth/Login.tsx @@ -139,26 +139,30 @@ class Login extends Component { {error.code === 'invalid-credentials' && ( <> -

+

{intl.formatMessage(messages.invalidCredentials)} -

+

{window['ferdium'].stores.settings.all.app.server !== LIVE_FRANZ_API && ( -

- {intl.formatMessage(messages.customServerQuestion)}{' '} - - {intl.formatMessage(messages.customServerSuggestion)} - -

+ <> +

+ {intl.formatMessage(messages.customServerQuestion)}{' '} +

+

+ + {intl.formatMessage(messages.customServerSuggestion)} + +

+ )} )} diff --git a/src/components/auth/Signup.tsx b/src/components/auth/Signup.tsx index fb2a2360e..06a9774aa 100644 --- a/src/components/auth/Signup.tsx +++ b/src/components/auth/Signup.tsx @@ -148,10 +148,10 @@ class Signup extends Component { showPasswordToggle scorePassword /> - {error.code === 'email-duplicate' && ( -

+ {error.status === 401 && ( +

{intl.formatMessage(messages.emailDuplicate)} -

+

)} {isSubmitting ? (