Commit 1829cef2 authored by Nikolai R Kristiansen's avatar Nikolai R Kristiansen

Handle different types of error responses

parent 256460f8
Pipeline #608 failed with stage
in 1 minute and 18 seconds
......@@ -155,6 +155,11 @@ export default class UserRegister extends Component {
const err = errors.non_field_errors;
let errorFormatted = err ? err[0] : 'Kunne ikke registrere bruker, prøv igjen...';
return <View style={styles.errorBox}><Text style={styles.errorMessage}>{errorFormatted}</Text></View>
} else if (Object.keys(errors).length !== 0 && 'detail' in errors) {
const err = errors.detail;
let errorFormatted = err ? err : 'Kunne ikke registrere bruker, prøv igjen...';
return <View style={styles.errorBox}><Text style={styles.errorMessage}>{errorFormatted}</Text></View>
}
return <View style={styles.errorBox}/>
......
......@@ -32,7 +32,7 @@ const initialState = {
function formatErrors(errs) {
let _errs = {};
for(let [key, value] of Object.entries(errs)) {
_errs[snakeToCamelCase(key)] = value.join('\n');
_errs[snakeToCamelCase(key)] = Array.isArray(value) ? value.join('\n') : value;
}
return _errs
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment