GrahamMorbyDev's avatar

FatalErrorException in OAuthExceptionHandlerMiddleware.php line 13:

Hey

I m running through a TuT on OAuth Api with Lumen and hit a snag

The TUT is here : http://esbenp.github.io/2015/05/26/lumen-web-api-oauth-2-authentication/

FatalErrorException in OAuthExceptionHandlerMiddleware.php line 13: Interface 'Illuminate\Contracts\Routing\Middleware' not found

<?php

namespace LucaDegasperi\OAuth2Server\Middleware;

use Closure;
use Illuminate\Http\JsonResponse;
use Illuminate\Contracts\Routing\Middleware;
use League\OAuth2\Server\Exception\OAuthException;

/*
* OAuthExceptionHandlerMiddleware
*/
class OAuthExceptionHandlerMiddleware implements Middleware
{
    public function handle($request, Closure $next)
    {
        try {

            return $next($request);

        } catch (OAuthException $e) {

            return new JsonResponse([
                    'error'             => $e->errorType,
                    'error_description' => $e->getMessage()
                ],
                $e->httpStatusCode,
                $e->getHttpHeaders()
            );
        }
    }
}

0 likes
5 replies
GrahamMorbyDev's avatar

ok cool

so my next question is how do i fix the file

I tried removing the class name and calling just middleware but fails and im at a loss on this now

tomopongrac's avatar

Does this work

namespace LucaDegasperi\OAuth2Server\Middleware;

use Closure;
use Illuminate\Http\JsonResponse;
use League\OAuth2\Server\Exception\OAuthException;

class OAuthExceptionHandlerMiddleware
{
    /**
     * Run the request filter.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
    try {

            return $next($request);

        } catch (OAuthException $e) {

            return new JsonResponse([
                    'error'             => $e->errorType,
                    'error_description' => $e->getMessage()
                ],
                $e->httpStatusCode,
                $e->getHttpHeaders()
            );
        }
    }

}
1 like
GrahamMorbyDev's avatar

It does, but looks like i may have this issue elsewhere with other files! I guess the only other way is to downgrade to 5.0 and start over

isust's avatar

hey,

i have the same issue today, is there any solution at the moment?

Please or to participate in this conversation.