i am trying to get the validations errros on signup but the flutter is just showing error code with the string but as we know laravel send whole array of errors which i am unable to get
here is my code
on<SignUpUser>( (event, emit) async {
final dio = getIt<Dio>();
dynamic result = await dio.post('/api/register', data: {
'name': event.name,
'email': event.email,
'password': event.password,
'password_confirmation': event.passwordConfirmation
},
options: Options(
// followRedirects: false,
// maxRedirects: 0,
// validateStatus: (status) => status! < 500,
headers: {
"Accept" : "application/json",
"Content-Type":"application/json"
},
),
);
// print(result.body);
if(result.statusCode == 422){
print(result.body['errors']); //print out validation errors
}
});
i have tried most of the stuff but not getting any understanding on this
2
Answers
you can simply use DioExceptions like this
}
but as we know laravel send whole array of errors[...]
– I don’t think that’s true. Sending a422
with no body should be the default behavior and is also the most secure thing to do. You can, however, return the the errors explicitly by adding aFormRequest
with a function like this one:See similar discussion here.