Skip to content

Commit

Permalink
[document_repository] Improper error handling #8760 (#8818)
Browse files Browse the repository at this point in the history
Return the proper HTTP response code when an error occurs in the document repository.

Resolves #8760
  • Loading branch information
kongtiaowang committed Jul 11, 2023
1 parent 4542f06 commit 23f6875
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
20 changes: 9 additions & 11 deletions modules/document_repository/jsx/uploadForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,17 +222,15 @@ class DocUploadForm extends Component {
);
});
} else {
resp.json().then((data) => {
console.error(resp);
swal.fire('Could not upload files', data.error, 'error');
}).catch((error) => {
console.error(error);
swal.fire(
'Error reading error response',
'Please report the issue or contact your administrator',
'error'
);
});
if (resp.status == 413) {
swal.fire('File too large', 'Could not upload file', 'error');
}
if (resp.status == 403) {
swal.fire('Permission denied',
'Could not upload file',
'error'
);
}
}
}).catch((error) => {
console.error(error);
Expand Down
10 changes: 4 additions & 6 deletions modules/document_repository/php/files.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,8 @@ class Files extends \NDB_Page
$name = $user->getUsername();

if (! $user->hasPermission('document_repository_edit')) {
return new \LORIS\Http\Response\JSON\Forbidden(
self::FORBIDDEN
);
header("HTTP/1.1 403 Forbidden");
exit;
}

// Do some validation and fail early on bad inputs.
Expand All @@ -328,9 +327,8 @@ class Files extends \NDB_Page
$uploadedFiles = $request->getUploadedFiles()['files'] ?? null;

if (is_null($uploadedFiles)) {
return new \LORIS\Http\Response\JSON\BadRequest(
'No files uploaded'
);
header("HTTP/1.1 413 Too_large");
exit;
}

$uploadedFiles = is_array($uploadedFiles)
Expand Down

0 comments on commit 23f6875

Please sign in to comment.