Fix docs drift and unify avatar API error envelope
This commit is contained in:
@@ -15,10 +15,7 @@ $request = requestInput();
|
||||
|
||||
$uuid = trim((string) ($id ?? ''));
|
||||
if ($uuid === '') {
|
||||
http_response_code(404);
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(['error' => 'not_found']);
|
||||
return;
|
||||
ApiResponse::notFound();
|
||||
}
|
||||
|
||||
$userAccountService = app(UserAccountService::class);
|
||||
@@ -36,26 +33,27 @@ $decision = $authorizationService->authorize(UserAuthorizationPolicy::ABILITY_AP
|
||||
|
||||
if (!$decision->isAllowed()) {
|
||||
$status = $decision->status() ?: 403;
|
||||
http_response_code($status);
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(['error' => $decision->error() ?: 'forbidden']);
|
||||
return;
|
||||
$error = $decision->error() ?: 'forbidden';
|
||||
|
||||
if ($status === 404) {
|
||||
ApiResponse::notFound($error);
|
||||
}
|
||||
|
||||
if ($status === 403) {
|
||||
ApiResponse::forbidden($error);
|
||||
}
|
||||
|
||||
ApiResponse::error($error, $status);
|
||||
}
|
||||
|
||||
if (!$user) {
|
||||
http_response_code(404);
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(['error' => 'not_found']);
|
||||
return;
|
||||
ApiResponse::notFound();
|
||||
}
|
||||
|
||||
$size = $request->hasQuery('size') ? $request->queryInt('size') : null;
|
||||
$path = $userAvatarService->findAvatarPath($uuid, $size);
|
||||
if (!$path || !is_file($path)) {
|
||||
http_response_code(404);
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(['error' => 'not_found']);
|
||||
return;
|
||||
ApiResponse::notFound();
|
||||
}
|
||||
|
||||
$mime = $userAvatarService->detectMime($path);
|
||||
|
||||
Reference in New Issue
Block a user