Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8741065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:14:31+00:00 2026-06-13T11:14:31+00:00

I have an application written with the Laravel PHP framework. My main application listens

  • 0

I have an application written with the Laravel PHP framework. My main application listens to the 404 and 500 events.

Event::listen('404', function()
{
    return Response::error('404');
});

Event::listen('500', function()
{
    return Response::error('500');
});

This show my custom error pages to the user. But now, I’ve also built an API, which lives in a bundle called api. This API will be used via Ajax, so I want to handle errors differently. So I added these events to the routes.php of the api bundle:

Event::listen('404', function()
{
    return Response::json(array('status' => 'error', 'message' => 'API endpoint not found.'));
});

Event::listen('500', function()
{
    return Response::json(array('status' => 'error', 'message' => 'Internal server error'));
});

Unfortunately, this doesn’t work, it still displays the HTML error page. How can I respond differently to 404/500 errors depending on API or main application?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T11:14:32+00:00Added an answer on June 13, 2026 at 11:14 am

    Have you tried overriding the main applications listeners from within your bundle? This should remove them as listeners when your bundle is called and leave only your bundles listeners for the events.

    You can override events using the Event::override() method instead of the listen method.

    Event::override('404', function()
    {
        return Response::json(array('status' => 'error', 'message' => 'API endpoint not found.'));
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application written in xcode/cocoa on Mac. A label on the main
I have application written in Zend Framework and structure is app/ application/ library/ public/
I have an application written in C#, using .Net 4.0 framework. As the application
I have an application written on top of the Zend Framework that is hosted
We have an application written in C#, using .NET Framework 3.0 or 3.5 or
I have an application written in C# targeting .NET Compact Framework 3.5, running on
I have an application written in PHP/Javascript which uses AJAX extensively. I am concerned
I have this application written in PHP, I'm considering on using eAccelerator for optimizing
I have an application written in C# targeting .NET Compact Framework 3.5, running on
I have an application written in C#.Net (Framework 2.0 if it matters). It calls

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.