I know this is quite an old question but I just stumbled across it.
By default Lumen will return a JSON response if the requester "wants" it.
vendor/laravel/lumen-framework/src/Exceptions/Handler.php:110
return $request->expectsJson()
? $this->prepareJsonResponse($request, $e)
: $this->prepareResponse($request, $e);
This goes down to
vendor/illuminate/http/Concerns/InteractsWithContentTypes.php:52
$acceptable = $this->getAcceptableContentTypes();
return isset($acceptable[0]) && Str::contains($acceptable[0], ['/json', '+json']);
Which means if you specify an "Accept" header for with "application/json" lumen will automatically return a JSON response.
e.g curl -H "Accept: application/json" https://example.com/my-erroring-endpint
Using this saves you from having to write a custom error handler.