mirror of
https://github.com/discourse/discourse.git
synced 2025-05-30 15:28:37 +08:00
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:
@ -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
|
||||
|
||||
|
Reference in New Issue
Block a user