display message on javascript error
Specifically this allows us to display an error message when the API is unavailable
This commit is contained in:
1 file changed
+13
-2
@@ -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}>
|
||||
|
||||
Reference in new issue
Block a user