Closed imhmdb closed 5 years ago
Got the same issue
[2019-09-27 10:30:34] local.ERROR: Return value of Scoutapm\Laravel\Middleware\MiddlewareInstrument::Scoutapm\Laravel\Middleware{closure}() must be an instance of Illuminate\Http\Response, instance of Illuminate\Http\JsonResponse returned {"exception":"[object] (Symfony\Component\Debug\Exception\FatalThrowableError(code: 0): Return value of Scoutapm\Laravel\Middleware\MiddlewareInstrument::Scoutapm\Laravel\Middleware\{closure}() must be an instance of Illuminate\Http\Response, instance of Illuminate\Http\JsonResponse returned at /home/vagrant/code/vendor/scoutapp/scout-apm-laravel/src/Middleware/MiddlewareInstrument.php:35) [stacktrace
Apologies this wasn't clear in implementing, nor does Laravel appear to provide an interface to define such requirements. Thanks for the fix! :+1:
the return type of the handle() method in a laravel Middleware should not be restricted to a Response object, it might also be ResponseJSON as seen on this error message that I got when testing this package:
local.ERROR: Return value of Scoutapm\Laravel\Middleware\MiddlewareInstrument::Scoutapm\Laravel\Middleware\{closure}() must be an instance of Illuminate\Http\Response, instance of Illuminate\Http\JsonResponse returned
also note that the default laravel middleware stub is stating that the return type of the handle() function is mixed https://github.com/laravel/framework/blob/c29c3c556fa3d0971421822f4980884640e74521/src/Illuminate/Routing/Console/stubs/middleware.stub#L14