Laravel Passport: Ignore login errors

At work we built a web application consisting of one backend that provides an API for user management and login via OAuth2, and a couple of frontend applications that all rely on that API.

For OAuth2, we used the Laravel 5.6 Passport library that brings all the OAuth2 server stuff we needed.

One issue we had were exceptions that occured in the API and were logged in our own Sentry instance: One entry for every user that mis-typed his password:


The user credentials were incorrect.

To solve this issue, we added the following code to our API application's exception handler:

     * Determine if the exception is in the "do not report" list.
     * @param Exception $e Exception to check
     * @return bool
    protected function shouldntReport(Exception $e)
        if ($e instanceof \League\OAuth2\Server\Exception\OAuthServerException) {
            //6: The user credentials were incorrect
            return $e->getCode() == 6;
        return parent::shouldntReport($e);

Written by Christian Weiske.

Comments? Please send an e-mail.