Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extra error handling for avatar file size & large payload #3042

Merged
merged 4 commits into from
Sep 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions js/src/common/Application.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,10 @@ export default class Application {
content = app.translator.trans('core.lib.error.not_found_message');
break;

case 413:
content = app.translator.trans('core.lib.error.payload_too_large_message');
break;

case 429:
content = app.translator.trans('core.lib.error.rate_limit_exceeded_message');
break;
Expand Down
1 change: 1 addition & 0 deletions locale/core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ core:
generic_message: "Oops! Something went wrong. Please reload the page and try again."
missing_dependencies_message: "Cannot enable {extension} until the following dependencies are enabled: {extensions}"
not_found_message: The requested resource was not found.
payload_too_large_message: The request payload was too large.
permission_denied_message: You do not have permission to do that.
rate_limit_exceeded_message: You're going a little too quickly. Please try again in a few seconds.

Expand Down
2 changes: 2 additions & 0 deletions locale/validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ validation:
ends_with: "The :attribute must end with one of the following: :values."
exists: "The selected :attribute is invalid."
file: "The :attribute must be a file."
file_too_large: "The :attribute is too large."
file_upload_failed: "The :attribute failed to upload."
filled: "The :attribute field must have a value."
gt:
numeric: "The :attribute must be greater than :value."
Expand Down
14 changes: 12 additions & 2 deletions src/User/AvatarValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,18 @@ public function assertValid(array $attributes)

protected function assertFileRequired(UploadedFileInterface $file)
{
if ($file->getError() !== UPLOAD_ERR_OK) {
$this->raise('required');
$error = $file->getError();

if ($error !== UPLOAD_ERR_OK) {
if ($error === UPLOAD_ERR_INI_SIZE || $error === UPLOAD_ERR_FORM_SIZE) {
$this->raise('file_too_large');
}

if ($error === UPLOAD_ERR_NO_FILE) {
$this->raise('required');
}

$this->raise('file_upload_failed');
}
}

Expand Down