mardi 4 juin 2019

Laravel throw a custom ValidationException

I'm trying to throw a custom exception. The project is consuming the 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.

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.

What am I doing wrong?



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2WrAfPl
via IFTTT

Aucun commentaire:

Enregistrer un commentaire