From 7c12fe1cbb0d6654bb388684792c25b0f2ab9724 Mon Sep 17 00:00:00 2001 From: Ethan Vizitei Date: Thu, 14 Jan 2021 11:12:17 -0600 Subject: [PATCH] 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 Tested-by: Service Cloud Jenkins QA-Review: Ethan Vizitei Product-Review: Ethan Vizitei --- lib/inst_fs.rb | 6 +++++- spec/lib/inst_fs_spec.rb | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/inst_fs.rb b/lib/inst_fs.rb index 26cea4f912e..686c50311df 100644 --- a/lib/inst_fs.rb +++ b/lib/inst_fs.rb @@ -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") diff --git a/spec/lib/inst_fs_spec.rb b/spec/lib/inst_fs_spec.rb index 977643ba955..66f585edd60 100644 --- a/spec/lib/inst_fs_spec.rb +++ b/spec/lib/inst_fs_spec.rb @@ -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