I'm trying to throw a custom exception. The project is an API consuming the Google Places API, and if the result has a status of ZERO RESULTS
I need to throw a validation exception. This is because the stored data is wrong.
To be more clear about this. A registered user modifies his profile which includes address, zip code, etc. Then we have a get method in which we make a query to the places API, this in order to get the latitude and longitude and add it to the profile model.
if (strcmp($status, 'ZERO_RESULTS') == 0 || strcmp($status, 'INVALID_REQUEST') == 0) {
$error = ValidationException::withMessages([
"one_thing" => ["Validation Message #1"], "another_thing" => ['Validation Message #2']
]);
throw $error;
}
I read some answers on StackOverflow and I'm even trying those answers but I'm only getting the following error:
{
"errors": [
{
"status": 500,
"code": 1,
"source": {
"pointer": "ErrorException line 73 in /Users/jacobotapia/Documents/Espora/one-mind-backend/vendor/sfelix-martins/json-exception-handler/src/ValidationHandler.php"
},
"title": "errorexception",
"detail": "Undefined index: one_thing"
}
]
}
Also I want to point that all the process occurs during a GET
method.
The only thing that I want is to return an error saying that we could not get any result from the google places API. This with the objective to say to the client that the profile data that the user registered in the app is wrong.
What am I doing wrong?