FIX: catch all server-side error when uploading a file

UX: always show a message to the user whenever an error happens on the server when uploading a file
This commit is contained in:
Régis Hanol
2017-12-27 16:33:25 +01:00
parent 805d1c25d3
commit f5e170c6b5
6 changed files with 34 additions and 28 deletions

View File

@ -26,17 +26,22 @@ class UploadsController < ApplicationController
# note, atm hijack is processed in its own context and has not access to controller
# longer term we may change this
hijack do
info = UploadsController.create_upload(
current_user: me,
file: file,
url: url,
type: type,
for_private_message: for_private_message,
pasted: pasted,
is_api: is_api,
retain_hours: retain_hours
)
render json: UploadsController.serialize_upload(info), status: Upload === info ? 200 : 422
begin
info = UploadsController.create_upload(
current_user: me,
file: file,
url: url,
type: type,
for_private_message: for_private_message,
pasted: pasted,
is_api: is_api,
retain_hours: retain_hours
)
rescue => e
render json: failed_json.merge(message: e.message&.split("\n")&.first), status: 422
else
render json: UploadsController.serialize_upload(info), status: Upload === info ? 200 : 422
end
end
end