wrap network errors to inst-fs in service exception

closes FOO-1467
flag=none

TEST PLAN:
  1) disable inst-fs
  2) network errors should get
    reported as service errors because
    we already have error paths for those.

Change-Id: Ib8cd10d05156b809e78602d24a6a6d92f10465ab
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/256728
Reviewed-by: Simon Williams <simon@instructure.com>
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
QA-Review: Ethan Vizitei <evizitei@instructure.com>
Product-Review: Ethan Vizitei <evizitei@instructure.com>
This commit is contained in:
Ethan Vizitei 2021-01-14 11:12:17 -06:00
parent a8133a1e3d
commit 7c12fe1cbb
2 changed files with 13 additions and 1 deletions

View File

@ -165,7 +165,11 @@ module InstFS
data = {}
data[file_name] = file_object
response = CanvasHttp.post(url, form_data: data, multipart: true, streaming: true)
begin
response = CanvasHttp.post(url, form_data: data, multipart: true, streaming: true)
rescue Net::ReadTimeout, CanvasHttp::CircuitBreakerError
raise InstFS::ServiceError, "unable to communicate with instfs"
end
if response.class == Net::HTTPCreated
json_response = JSON.parse(response.body)
return json_response["instfs_uuid"] if json_response.key?("instfs_uuid")

View File

@ -545,6 +545,14 @@ describe InstFS do
file_object: File.open("public/images/a.png")
)
end
it "wraps network errors in a service exception" do
instfs_uuid = "1234-abcd"
allow(CanvasHttp).to receive(:post).and_raise(Net::ReadTimeout)
expect do
InstFS.direct_upload(file_name: "a.png", file_object: File.open("public/images/a.png"))
end.to raise_error(InstFS::ServiceError)
end
end
context "duplicate" do