mercredi 29 mars 2017

return a json error in middleware?

I'm building an app and I'm using laravel5 as webAPI. When the webAPI is in Maintenance Mode, I want to return a json error to app and I will get the status code in app to show a suitable message.

I rewrite the laravel CheckForMaintenanceMode for somereason and registed it in Kernel.

I write

if ($this->app->isDownForMaintenance()) {
    $ip = $request->getClientIp();
    $allowIp = "111.222.333.444";
    if ($allowIp != $ip) {
        return response()->json(['error' => "Maintenance!!"], 503);
    }
}
return $next($request);

But I can get NOTHING in app side.I cannot get the message, the satus....

I writh the same code like return response()->json(['error' => "errormessage"], 422); in controller and I can get the message.status.. in app but I cannot do the same thing in a middleware.

why? how to do it?



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

Aucun commentaire:

Enregistrer un commentaire