I have a controller in Laravel 5.8 that creates a campaign from all requested input. It runs through a try/catch
routine and all going well, spits me out the returned database record.
try {
// Create the new Campaign record
$campaign = Campaign::create( $request->all() );
}
catch( exception $e ) {
return response()->json( '(' . $e->getCode() . ')' . ' ' . $e->getMessage(), 400 );
}
return response()->json( $campaign, 200 );
However, I have come across a problem where Laravel is returning a 'generic' error to my AngularJS application.
When I attempt the $http
request in my AngularJS frontend, I get the following error returned: (0) Array to string conversion
(Bad Request - Error 400).
When I attempt the request through a 3rd party app (such as Google Advanced REST Client), I get a different error: (22007) SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '2020-07-05T15:30:04.095Z' for column 'StartTime' at row 1
I have tried removing the try/catch
and even tried removing the $e
message, but I still get the same generic error returned to Angular.
Could someone please tell me why I cannot see the correct error here. I am trying to give reasonable feedback back to my users, but that generic error helps no one. I spent ages looking for an array conversion error in my code, but having the correct error to begin with would've saved me a lot of time debugging.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire