Skip to content

Commit

Permalink
fix(Middleware): return reasonable status codes
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
  • Loading branch information
blizzz committed Apr 30, 2024
1 parent d9fd0a2 commit 399e78c
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/Middleware/PermissionMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
namespace OCA\Tables\Middleware;

use OCA\Tables\Errors\InternalError;
use OCA\Tables\Errors\NotFoundError;
use OCA\Tables\Errors\PermissionError;
use OCA\Tables\Service\PermissionsService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Middleware;
use OCP\AppFramework\Utility\IControllerMethodReflector;
use OCP\IRequest;
Expand Down Expand Up @@ -87,4 +90,14 @@ protected function assertCanManageContext(): void {
}
}
}

public function afterException(Controller $controller, string $methodName, \Exception $exception) {
if ($exception instanceof PermissionError) {
return new Http\DataResponse(['message' => $exception->getMessage()], Http::STATUS_FORBIDDEN);
}
if ($exception instanceof NotFoundError) {
return new Http\DataResponse(['message' => $exception->getMessage()], Http::STATUS_NOT_FOUND);
}
throw $exception;
}
}

0 comments on commit 399e78c

Please sign in to comment.