display message on javascript error

Specifically this allows us to display an error message when the API is
unavailable
This commit is contained in:
leander committed 2024-07-26 03:04:08 +02:00
1 parent 8ed6e30da1
commit e8bb66b740
1 file changed
+13 -2
+13 -2
View File
@@ -4,13 +4,24 @@ import { Text, StyleSheet, View } from 'react-native';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const FormErrors = ({ errors }: { errors: Record<string, any> }) => {
if (!errors) {
return;
}
let errorFormatted;
if ('non_field_errors' in errors) {
if (errors instanceof Error) {
// This check might backfire on us as it's too general. We do not wish to display the error message to the user
// Hence we display this generic one
errorFormatted = 'Kunne ikke sende inn skjemaet! Prøv igjen senere...';
} else if ('non_field_errors' in errors) {
errorFormatted = errors.non_field_errors?.[0];
} else if ('detail' in errors) {
errorFormatted = errors.detail;
}
if (!errorFormatted) errorFormatted = 'Kunne ikke sende inn skjemaet! Prøv igjen senere...';
if (!errorFormatted) {
return;
}
return (
<View style={styles.container}>