From 00433ee7ba7584ddd58a4f4051b9572ac8bcde60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Tue, 28 Nov 2023 17:55:40 +0100 Subject: [PATCH] Some fixes for API log error --- front/API.ts | 11 ++++++----- front/components/UI/ButtonBase.tsx | 6 ++---- front/components/UI/ScaffoldAuth.tsx | 10 ++++++++-- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/front/API.ts b/front/API.ts index a80283f..286d272 100644 --- a/front/API.ts +++ b/front/API.ts @@ -67,7 +67,9 @@ export class ValidationError extends Error { export default class API { public static readonly baseUrl = - Platform.OS === 'web' && !process.env.EXPO_PUBLIC_API_URL ? '/api' : process.env.EXPO_PUBLIC_API_URL!; + Platform.OS === 'web' && !process.env.EXPO_PUBLIC_API_URL + ? '/api' + : process.env.EXPO_PUBLIC_API_URL!; public static async fetch( params: FetchParams, handle: Pick, 'raw'> @@ -114,11 +116,11 @@ export default class API { } const handler = handle.handler; const body = await response.text(); + if (!response.ok) { + throw new APIError(response.statusText ?? body, response.status, 'unknownError'); + } try { const jsonResponse = JSON.parse(body); - if (!response.ok) { - throw new APIError(response.statusText ?? body, response.status, 'unknownError'); - } const validated = await handler.validator.validate(jsonResponse).catch((e) => { if (e instanceof yup.ValidationError) { console.error(e, 'Got: ' + body); @@ -151,7 +153,6 @@ export default class API { /// We want that 401 error to be thrown, instead of the plain validation vone if (e.status == 401) throw new APIError('invalidCredentials', 401, 'invalidCredentials'); - if (!(e instanceof APIError)) throw e; throw e; }); } diff --git a/front/components/UI/ButtonBase.tsx b/front/components/UI/ButtonBase.tsx index 039edd7..833835c 100644 --- a/front/components/UI/ButtonBase.tsx +++ b/front/components/UI/ButtonBase.tsx @@ -148,10 +148,7 @@ const ButtonBase: React.FC = ({ )} {iconImage && } {title && ( - + {title} )} @@ -176,6 +173,7 @@ const styles = StyleSheet.create({ height: 18, }, text: { + userSelect: 'none', marginHorizontal: 8, }, }); diff --git a/front/components/UI/ScaffoldAuth.tsx b/front/components/UI/ScaffoldAuth.tsx index 2413c41..5a31f29 100644 --- a/front/components/UI/ScaffoldAuth.tsx +++ b/front/components/UI/ScaffoldAuth.tsx @@ -72,7 +72,7 @@ const ScaffoldAuth: FunctionComponent = ({ Chromacase logo = ({ }} /> {layout.width > 650 && ( - + ChromaCase )}