Skip to content
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

Conversation

butonic
Copy link
Member

@butonic butonic commented Apr 1, 2015

starting point for #15332 (comment) feel free to hijack.

@butonic
Copy link
Member Author

butonic commented Apr 1, 2015

cc @nickvergessen @LukasReschke

*/
public function isJSONRequest() {
if (stristr($_SERVER['HTTP_X_REQUEST_WITH'], 'XMLHttpRequest')
|| stristr($_SERVER['HTTP_ACCEPT'],'application/json')
Copy link
Member

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]

@butonic butonic force-pushed the dont_send_errors_as_html_if_request_looks_like_a_json_request_master branch from 46a6424 to 15d7825 Compare April 1, 2015 11:46
@@ -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()) {
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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

@scrutinizer-notifier
Copy link

The inspection completed: 2 new issues, 1 updated code elements

@PVince81
Copy link
Contributor

PVince81 commented Jul 3, 2015

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.
Most of the time non-setup errors happen during ajax operations or webdav.
Maybe we should make JSON and co the default and make a special case for the other one ?

@DeepDiver1975
Copy link
Member

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

@PVince81
Copy link
Contributor

PVince81 commented Sep 1, 2015

Any update for this ?

@MorrisJobke
Copy link
Contributor

No activity -> 9.0

@DeepDiver1975 DeepDiver1975 force-pushed the dont_send_errors_as_html_if_request_looks_like_a_json_request_master branch from 15d7825 to 5e24d29 Compare January 13, 2016 12:32
} 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()) {
Copy link
Member

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

@butonic

@MorrisJobke MorrisJobke mentioned this pull request Jan 19, 2016
@MorrisJobke
Copy link
Contributor

Fixes #10134

@PVince81 PVince81 modified the milestones: 9.1-next, 9.0-current Feb 11, 2016
@PVince81
Copy link
Contributor

We're past feature freeze, changing base.php or base interfaces can be dangerous.

Moving to 9.1

CC @cmonteroluque

@PVince81
Copy link
Contributor

Is this critical enough to push this forward ?
If yes, please rebase and review.

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)
@DeepDiver1975 @butonic

@DeepDiver1975
Copy link
Member

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?

@DeepDiver1975
Copy link
Member

lets reopen this one day ....

@DeepDiver1975 DeepDiver1975 deleted the dont_send_errors_as_html_if_request_looks_like_a_json_request_master branch May 30, 2016 20:56
@lock
Copy link

lock bot commented Aug 5, 2019

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.

@lock lock bot locked as resolved and limited conversation to collaborators Aug 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants