Skip to content

Commit

Permalink
fix(Contexts): fix return code when context not found
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 Mar 6, 2024
1 parent 5660cf7 commit 0d141de
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/Controller/ContextController.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public function show(int $contextId): DataResponse {
try {
$context = $this->contextService->findById($contextId, $this->userId);
return new DataResponse($context->jsonSerialize());
} catch (NotFoundError $e) {
return $this->handleNotFoundError($e);

Check failure on line 76 in lib/Controller/ContextController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

InvalidReturnStatement

lib/Controller/ContextController.php:76:11: InvalidReturnStatement: The inferred type 'OCP\AppFramework\Http\DataResponse<404, array{message: string}, array<never, never>>' does not match the declared return type 'OCP\AppFramework\Http\DataResponse<200|500, array{description?: string, iconName?: string, id?: int, message?: string, name?: string, owner?: string, ownerType?: int}, array<never, never>>' for OCA\Tables\Controller\ContextController::show (see https://psalm.dev/128)

Check failure on line 76 in lib/Controller/ContextController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable28

InvalidReturnStatement

lib/Controller/ContextController.php:76:11: InvalidReturnStatement: The inferred type 'OCP\AppFramework\Http\DataResponse<404, array{message: string}, array<never, never>>' does not match the declared return type 'OCP\AppFramework\Http\DataResponse<200|500, array{description?: string, iconName?: string, id?: int, message?: string, name?: string, owner?: string, ownerType?: int}, array<never, never>>' for OCA\Tables\Controller\ContextController::show (see https://psalm.dev/128)
} catch (InternalError|Exception $e) {
return $this->handleError($e);
}
Expand Down
5 changes: 5 additions & 0 deletions lib/Db/ContextMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace OCA\Tables\Db;

use OCA\Tables\Errors\NotFoundError;
use OCA\Tables\Helper\UserHelper;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
Expand Down Expand Up @@ -172,6 +173,10 @@ public function findById(int $contextId, ?string $userId = null): Context {
$result = $qb->executeQuery();
$r = $result->fetchAll();

if (empty($r)) {
throw new NotFoundError('Context does not exist');
}

return $this->formatResultRows($r, $userId);
}

Expand Down

0 comments on commit 0d141de

Please sign in to comment.