Merge pull request #26846 from nextcloud/followup/26572/reply-with-json-when-not-accepting-html
Reply with json when not accepting html on LoginException
This commit is contained in:
commit
77a4368418
|
@ -688,4 +688,4 @@ Feature: provisioning
|
||||||
And assure user "user0" is disabled
|
And assure user "user0" is disabled
|
||||||
And As an "user0"
|
And As an "user0"
|
||||||
When sending "GET" with exact url to "/index.php/apps/files"
|
When sending "GET" with exact url to "/index.php/apps/files"
|
||||||
And the HTTP status code should be "403"
|
And the HTTP status code should be "401"
|
||||||
|
|
14
index.php
14
index.php
|
@ -55,7 +55,19 @@ try {
|
||||||
OC_Template::printExceptionErrorPage($ex, 500);
|
OC_Template::printExceptionErrorPage($ex, 500);
|
||||||
}
|
}
|
||||||
} catch (\OC\User\LoginException $ex) {
|
} catch (\OC\User\LoginException $ex) {
|
||||||
OC_Template::printErrorPage($ex->getMessage(), $ex->getMessage(), 403);
|
$request = \OC::$server->getRequest();
|
||||||
|
/**
|
||||||
|
* Routes with the @CORS annotation and other API endpoints should
|
||||||
|
* not return a webpage, so we only print the error page when html is accepted,
|
||||||
|
* otherwise we reply with a JSON array like the SecurityMiddleware would do.
|
||||||
|
*/
|
||||||
|
if (stripos($request->getHeader('Accept'),'html') === false) {
|
||||||
|
http_response_code(401);
|
||||||
|
header('Content-Type: application/json; charset=utf-8');
|
||||||
|
echo json_encode(['message' => $ex->getMessage()]);
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
OC_Template::printErrorPage($ex->getMessage(), $ex->getMessage(), 401);
|
||||||
} catch (Exception $ex) {
|
} catch (Exception $ex) {
|
||||||
\OC::$server->getLogger()->logException($ex, ['app' => 'index']);
|
\OC::$server->getLogger()->logException($ex, ['app' => 'index']);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue