Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f05a1c5dad | ||
|
|
bfbac67d2a | ||
|
|
2d763ae1b0 | ||
|
|
12d47f1159 | ||
|
|
d9b0e60cd8 | ||
|
|
9d57a380f7 |
16
CHANGELOG.md
16
CHANGELOG.md
@@ -1,6 +1,22 @@
|
||||
# Changelog
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
## 1.2.11
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fix release asset build
|
||||
|
||||
## 1.2.10
|
||||
|
||||
### Fixed
|
||||
|
||||
- #3394 Use displayname instead of uid for mentions (reopened against master)
|
||||
|
||||
### Other
|
||||
|
||||
- #3409 Keep exceptions http response generic
|
||||
|
||||
|
||||
## 1.2.9
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
- 🚀 Get your project organized
|
||||
|
||||
</description>
|
||||
<version>1.2.9</version>
|
||||
<version>1.2.11</version>
|
||||
<licence>agpl</licence>
|
||||
<author>Julius Härtl</author>
|
||||
<namespace>Deck</namespace>
|
||||
|
||||
@@ -32,6 +32,7 @@ use OCP\AppFramework\Http\JSONResponse;
|
||||
use OCP\AppFramework\OCS\OCSException;
|
||||
use OCP\AppFramework\OCSController;
|
||||
use OCP\ILogger;
|
||||
use OCP\IRequest;
|
||||
use OCP\Util;
|
||||
use OCP\IConfig;
|
||||
|
||||
@@ -41,6 +42,8 @@ class ExceptionMiddleware extends Middleware {
|
||||
private $logger;
|
||||
/** @var IConfig */
|
||||
private $config;
|
||||
/** @var IRequest */
|
||||
private $request;
|
||||
|
||||
/**
|
||||
* SharingMiddleware constructor.
|
||||
@@ -48,9 +51,10 @@ class ExceptionMiddleware extends Middleware {
|
||||
* @param ILogger $logger
|
||||
* @param IConfig $config
|
||||
*/
|
||||
public function __construct(ILogger $logger, IConfig $config) {
|
||||
public function __construct(ILogger $logger, IConfig $config, IRequest $request) {
|
||||
$this->logger = $logger;
|
||||
$this->config = $config;
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,43 +71,10 @@ class ExceptionMiddleware extends Middleware {
|
||||
throw $exception;
|
||||
}
|
||||
|
||||
if ($exception instanceof ConflictException) {
|
||||
if ($this->config->getSystemValue('loglevel', Util::WARN) === Util::DEBUG) {
|
||||
$this->logger->logException($exception);
|
||||
}
|
||||
return new JSONResponse([
|
||||
'status' => $exception->getStatus(),
|
||||
'message' => $exception->getMessage(),
|
||||
'data' => $exception->getData(),
|
||||
], $exception->getStatus());
|
||||
}
|
||||
|
||||
if ($exception instanceof StatusException) {
|
||||
if ($this->config->getSystemValue('loglevel', Util::WARN) === Util::DEBUG) {
|
||||
$this->logger->logException($exception);
|
||||
}
|
||||
|
||||
if ($controller instanceof OCSController) {
|
||||
$exception = new OCSException($exception->getMessage(), $exception->getStatus(), $exception);
|
||||
throw $exception;
|
||||
}
|
||||
return new JSONResponse([
|
||||
'status' => $exception->getStatus(),
|
||||
'message' => $exception->getMessage()
|
||||
], $exception->getStatus());
|
||||
}
|
||||
|
||||
if (strpos(get_class($controller), 'OCA\\Deck\\Controller\\') === 0) {
|
||||
$response = [
|
||||
'status' => 500,
|
||||
'message' => $exception->getMessage()
|
||||
];
|
||||
$this->logger->logException($exception);
|
||||
if ($this->config->getSystemValue('debug', true) === true) {
|
||||
$response['exception'] = (array) $exception;
|
||||
}
|
||||
return new JSONResponse($response, 500);
|
||||
}
|
||||
$debugMode = $this->config->getSystemValue('debug', false);
|
||||
$exceptionMessage = $debugMode !== true
|
||||
? 'Internal server error: Please contact the server administrator if this error reappears multiple times, please include the request ID "' . $this->request->getId() . '" below in your report.'
|
||||
: $exception->getMessage();
|
||||
|
||||
// uncatched DoesNotExistExceptions will be thrown when the main entity is not found
|
||||
// we return a 403 so we don't leak information over existing entries
|
||||
@@ -114,6 +85,43 @@ class ExceptionMiddleware extends Middleware {
|
||||
'message' => 'Permission denied'
|
||||
], 403);
|
||||
}
|
||||
|
||||
if ($exception instanceof StatusException) {
|
||||
if ($this->config->getSystemValue('loglevel', Util::WARN) === Util::DEBUG) {
|
||||
$this->logger->logException($exception);
|
||||
}
|
||||
|
||||
if ($exception instanceof ConflictException) {
|
||||
return new JSONResponse([
|
||||
'status' => $exception->getStatus(),
|
||||
'message' => $exception->getMessage(),
|
||||
'data' => $exception->getData(),
|
||||
], $exception->getStatus());
|
||||
}
|
||||
|
||||
if ($controller instanceof OCSController) {
|
||||
$exception = new OCSException($exception->getMessage(), $exception->getStatus(), $exception);
|
||||
throw $exception;
|
||||
}
|
||||
|
||||
return new JSONResponse([
|
||||
'status' => $exception->getStatus(),
|
||||
'message' => $exception->getMessage(),
|
||||
], $exception->getStatus());
|
||||
}
|
||||
|
||||
if (strpos(get_class($controller), 'OCA\\Deck\\Controller\\') === 0) {
|
||||
$response = [
|
||||
'status' => 500,
|
||||
'message' => $exceptionMessage,
|
||||
'requestId' => $this->request->getId(),
|
||||
];
|
||||
$this->logger->logException($exception);
|
||||
if ($debugMode === true) {
|
||||
$response['exception'] = (array) $exception;
|
||||
}
|
||||
return new JSONResponse($response, 500);
|
||||
}
|
||||
|
||||
throw $exception;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,12 @@
|
||||
|
||||
namespace OCA\Deck;
|
||||
|
||||
/**
|
||||
* User facing exception that can be thrown with an error being reported to the frontend
|
||||
* or consumers of the API
|
||||
*
|
||||
* This exception is catched in the ExceptionMiddleware
|
||||
*/
|
||||
class StatusException extends \Exception {
|
||||
public function __construct($message) {
|
||||
parent::__construct($message);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "deck",
|
||||
"description": "",
|
||||
"version": "1.2.9",
|
||||
"version": "1.2.11",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Julius Härtl",
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
<At ref="at"
|
||||
v-model="commentText"
|
||||
:members="members"
|
||||
name-key="uid"
|
||||
name-key="displayname"
|
||||
:tab-select="true">
|
||||
<template v-slot:item="s">
|
||||
<Avatar class="atwho-li--avatar" :user="s.item.uid" :size="24" />
|
||||
|
||||
@@ -47,10 +47,12 @@ class ExceptionMiddlewareTest extends \Test\TestCase {
|
||||
public function setUp(): void {
|
||||
$this->logger = $this->createMock(ILogger::class);
|
||||
$this->config = $this->createMock(IConfig::class);
|
||||
$this->request = $this->createMock(IRequest::class);
|
||||
$this->controller = $this->createMock(Controller::class);
|
||||
$this->exceptionMiddleware = new ExceptionMiddleware(
|
||||
$this->logger,
|
||||
$this->config
|
||||
$this->config,
|
||||
$this->request
|
||||
);
|
||||
}
|
||||
|
||||
@@ -81,10 +83,11 @@ class ExceptionMiddlewareTest extends \Test\TestCase {
|
||||
}
|
||||
|
||||
public function testAfterExceptionFail() {
|
||||
$this->request->expects($this->any())->method('getId')->willReturn('abc123');
|
||||
// BoardService $boardService, PermissionService $permissionService, $userId
|
||||
$boardController = new BoardController('deck', $this->createMock(IRequest::class), $this->createMock(BoardService::class), $this->createMock(PermissionService::class), 'admin');
|
||||
$result = $this->exceptionMiddleware->afterException($boardController, 'bar', new \Exception('failed hard'));
|
||||
$this->assertEquals('failed hard', $result->getData()['message']);
|
||||
$result = $this->exceptionMiddleware->afterException($boardController, 'bar', new \Exception('other exception message'));
|
||||
$this->assertEquals('Internal server error: Please contact the server administrator if this error reappears multiple times, please include the request ID "abc123" below in your report.', $result->getData()['message']);
|
||||
$this->assertEquals(500, $result->getData()['status']);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user