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 9091173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:32:49+00:00 2026-06-16T22:32:49+00:00

I’m developing a heavy AJAX Symfony 2 app. Most of my actions begin this

  • 0

I’m developing a heavy AJAX Symfony 2 app. Most of my actions begin this way:

if($this->getRequest()->isXmlHttpRequest()) {
   // Do something
}

The action only must be executed in case it’s responding to an AJAX request. I thought it would be better for sake of simplicity and better indentation to do things this way:

if(false === $this->getRequest()->isXmlHttpRequest()) {
   // throw some exception
}

// Do something

My problem is I don’t know what’s the most appropiate Exception I could throw. I’d like to get some feedback on the subject. Maybe AccessDeniedException? Would any of Symfony predefined Exception fit? Or should I create a new Exception extending the base PHP Exception class? Any opinions will be really appreciated and sorry for my English.


Edit: What about this one?

https://github.com/symfony/HttpKernel/blob/master/Exception/BadRequestHttpException.php

  • 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-16T22:32:51+00:00Added an answer on June 16, 2026 at 10:32 pm

    You didn’t mention authentication, so I’m assuming it’s not an issue here. That being the case, I wouldn’t use AccessDeniedException, since it will produce a 401 Unauthorized error, which means that the user’s credentials were incorrect or missing. Here’s the definition for the 401 Unauthorized status:

    The request requires user authentication. The response MUST include a WWW-Authenticate header field (section 14.47) containing a challenge applicable to the requested resource. The client MAY repeat the request with a suitable Authorization header field (section 14.8). If the request already included Authorization credentials, then the 401 response indicates that authorization has been refused for those credentials. If the 401 response contains the same challenge as the prior response, and the user agent has already attempted authentication at least once, then the user SHOULD be presented the entity that was given in the response, since that entity might include relevant diagnostic information. HTTP access authentication is explained in “HTTP Authentication: Basic and Digest Access Authentication” [43].

    I also wouldn’t go with BadRequestHttpException. That will return a 400 response, which means that the server didn’t understand the request. I think in this case, the server understands the request, but is refusing to fulfill it. Here’s the full definition for a 400 response:

    The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request without modifications.

    I think the HTTP status that closest matches your case here is 403 Forbidden:

    The server understood the request, but is refusing to fulfill it. Authorization will not help and the request SHOULD NOT be repeated. If the request method was not HEAD and the server wishes to make public why the request has not been fulfilled, it SHOULD describe the reason for the refusal in the entity. If the server does not wish to make this information available to the client, the status code 404 (Not Found) can be used instead.

    According to Symfony on github, it doesn’t look like Symfony has a ForbiddenException, or anything similar… Which I think is a little strange (maybe I’m missing something?).

    If that’s the case, you can write your own, implementing the HttpExceptionInterface (or simply by extending HttpException). That, or you can just create a generic one on the fly:

    throw new HttpException(403, "Forbidden");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms
I know there's a lot of other questions out there that deal with this

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.