Some fixes for API log error
This commit is contained in:
11
front/API.ts
11
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<Required<HandleParams>, '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;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -148,10 +148,7 @@ const ButtonBase: React.FC<ButtonProps> = ({
|
||||
)}
|
||||
{iconImage && <Image source={{ uri: iconImage }} style={styles.icon} />}
|
||||
{title && (
|
||||
<Text
|
||||
style={[styles.text, type === 'filled' ? { color: '#fff' } : {}]}
|
||||
selectable={false}
|
||||
>
|
||||
<Text style={[styles.text, type === 'filled' ? { color: '#fff' } : {}]}>
|
||||
{title}
|
||||
</Text>
|
||||
)}
|
||||
@@ -176,6 +173,7 @@ const styles = StyleSheet.create({
|
||||
height: 18,
|
||||
},
|
||||
text: {
|
||||
userSelect: 'none',
|
||||
marginHorizontal: 8,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -72,7 +72,7 @@ const ScaffoldAuth: FunctionComponent<ScaffoldAuthProps> = ({
|
||||
<Row space={2} flex={1}>
|
||||
<Image
|
||||
source={{ uri: logo?.at(0)?.uri }}
|
||||
alt='Chromacase logo'
|
||||
alt="Chromacase logo"
|
||||
style={{
|
||||
aspectRatio: 1,
|
||||
width: 32,
|
||||
@@ -80,7 +80,13 @@ const ScaffoldAuth: FunctionComponent<ScaffoldAuthProps> = ({
|
||||
}}
|
||||
/>
|
||||
{layout.width > 650 && (
|
||||
<Text fontSize={'xl'} selectable={false}>
|
||||
<Text
|
||||
fontSize={'xl'}
|
||||
style={{
|
||||
// @ts-expect-error - RNW does not have userSelect
|
||||
userSelect: 'none',
|
||||
}}
|
||||
>
|
||||
ChromaCase
|
||||
</Text>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user