-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't send errors as HTML if request looks like a json request #15357
Don't send errors as HTML if request looks like a json request #15357
Conversation
*/ | ||
public function isJSONRequest() { | ||
if (stristr($_SERVER['HTTP_X_REQUEST_WITH'], 'XMLHttpRequest') | ||
|| stristr($_SERVER['HTTP_ACCEPT'],'application/json') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should use this->server['HTTP_ACCEPT]
46a6424
to
15d7825
Compare
@@ -44,14 +44,20 @@ | |||
|
|||
//show the user a detailed error page | |||
OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE); | |||
OC_Template::printExceptionErrorPage($ex); | |||
if (\OC::$server->getRequest()->isJSONRequest()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about moving this check inside printExceptionErrorPage() adn even send back the error message as json?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this looks ugly. But as a developer you expect printExceptionErrorPage() to output something ... it starts with print.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it starts with print.
in case of json request it will print out json - on cli it will print out plain text - html for all the rest
The inspection completed: 2 new issues, 1 updated code elements |
Sometimes I have the feeling that showing an exception page is really a corner case that happens only at setup time or if something is wrong with the setup. |
I'd like to have a solution which somewhat merges with this last-minute-8.1-hack - https://github.com/owncloud/core/blob/master/remote.php#L43 |
Any update for this ? |
No activity -> 9.0 |
15d7825
to
5e24d29
Compare
} catch (Exception $ex) { | ||
\OCP\Util::logException('index', $ex); | ||
|
||
//show the user a detailed error page | ||
OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR); | ||
OC_Template::printExceptionErrorPage($ex); | ||
if (\OC::$server->getRequest()->isJSONRequest()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be inverted - right?
If it's NOT a json request the exception page is displayed
Fixes #10134 |
We're past feature freeze, changing base.php or base interfaces can be dangerous. Moving to 9.1 CC @cmonteroluque |
Is this critical enough to push this forward ? Else let's close this and schedule time for a proper discussion about the approach we want here (which we could track in a ticket) |
@butonic agree to close? |
lets reopen this one day .... |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
starting point for #15332 (comment) feel free to hijack.