scoutapp / scout-apm-laravel

ScoutAPM PHP Agent for the Laravel Framework
MIT License
22 stars 12 forks source link

Remove Response type restrictions on middlewares #21

Closed imhmdb closed 5 years ago

imhmdb commented 5 years ago

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

Christophvh commented 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

asgrim commented 5 years ago

Apologies this wasn't clear in implementing, nor does Laravel appear to provide an interface to define such requirements. Thanks for the fix! :+1: