Laravel "throw" with ValidationException return 500 insteed 422?

Viewed 125

I have login, register and restore form in Laravel 5.8 App. When i'm trying to submit form data, server return 500 error.

The last method of the operation I found:

protected function sendFailedLoginResponse(Request $request)
{
    throw ValidationException::withMessages([
        $this->username() => [trans('Неверный логин или пароль, проверьте <br> введённые данные и нажмите «Вход» ещё раз')],
    ]);
}

I tried to dump ValidationException without "throw", and he return correct data.

For example:

ValidationException {#455 ▼
  +validator: Validator {#451 ▼
    #translator: Translator {#200 ▶}
    #container: Application {#2 ▶}
    #presenceVerifier: DatabasePresenceVerifier {#438 ▶}
    #failedRules: []
    #messages: MessageBag {#448 ▼
      #messages: array:1 [▼
        "email" => array:1 [▼
          0 => "Неверный логин или пароль, проверьте <br> введённые данные и нажмите «Вход» ещё раз"
        ]
      ]
      #format: ":message"
    }
    #data: []
    #initialRules: []
    #rules: []
    #currentRule: null
    #implicitAttributes: []
    #distinctValues: []
    #after: []
    +customMessages: []
    +fallbackMessages: []
    +customAttributes: []
    +customValues: []
    +extensions: []
    +replacers: []
    #fileRules: array:9 [▶]
    #implicitRules: array:10 [▶]
    #dependentRules: array:18 [▶]
    #sizeRules: array:8 [▶]
    #numericRules: array:2 [▶]
  }
  +response: null
  +status: 422
  +errorBag: "default"
  +redirectTo: null
  #message: "The given data was invalid."
  #code: 0
  #file: "/home/v/vladish1/xenforo.ws/public_html/vendor/laravel/framework/src/Illuminate/Validation/ValidationException.php"
  #line: 71
  trace: {▶}
}

But with "throw" server return 500. Why? What I'm doing wrong?

0 Answers
Related