nkuhta
nkuhta

Reputation: 11148

Simple error response in Laravel 5 while JSON request

I have project on Laravel 5, and I need to do async request via jQuery's $.ajax method. Laravel can catch exception, and then it render special error template with it's own styles and markup. But for async requests this html-code is redundant. Is there a way to generate error response without laravel's markup on async requests?

Upvotes: 2

Views: 947

Answers (1)

Sulthan Allaudeen
Sulthan Allaudeen

Reputation: 11320

I guess you wanted this to write the web service.

To handle this

Goto app/Exceptions/Handler.php :

And change this function

public function render($request, Exception $e)
    {
        return parent::render($request, $e);
    }

to

public function render($request, Exception $e)
    {
        if ($this->isHttpException($e))
        {
            return $this->renderHttpException($e);
        }
        else
        {
            return parent::render($request, $e);
        }
    }

Also if you need to customize in the webview

Change your 404 blade \resources\views\errors\404.blade.php here

Upvotes: 2

Related Questions