vendredi 21 août 2015

Laravel 5 after middleware not ran after Exception is raised

When using an after middleware to transform data (success() is a custom helper that does stuffs):

<?php namespace Acmelab\Slz\Middleware;

use Closure;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Response;

/**
 * This middleware force all requests to be rendered
 * as a json object (simulate ajax on every request).
 * @package Acmelab\Slz\Middleware
 */
class Serializer
{
    /**
     * Handle an incoming request.
     * @param  \Illuminate\Http\Request $request
     * @param  \Closure $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        /** @var Response $response */
        $response = $next($request);

        // exceptions are handled in Exceptions/Handler
        // so here we have only successfull requests coming in
        return success($response->getOriginalContent(), $response->getStatusCode());
    }
}

The part of the middleware after $response = $next($request); is never ran if an exception is handled this way (in the exception handler):

public function render($request, Exception $e)
{
    return response(get_class($e), 403);
}

In any other case the code is ran (if I ran this from a controller for instance):

public function postAction() {
    return response($stringOrArray);
}

Is this a bug ? Why I cannot transform the result of the response returned while handling my exception ?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1TXvg0Y
via IFTTT

Aucun commentaire:

Enregistrer un commentaire