A platform for community discussion. Free, open, simple.
FIX: Rescue and display import errors when updating theme via git
David Taylor7b7bc3db39fc
diff --git a/app/controllers/admin/themes_controller.rb b/app/controllers/admin/themes_controller.rbindex f927eee3374..31bda272ded 100644--- a/app/controllers/admin/themes_controller.rb+++ b/app/controllers/admin/themes_controller.rb@@ -209,6 +209,8 @@ class Admin::ThemesController < Admin::AdminControllerendendend+ rescue RemoteTheme::ImportError => e+ render_json_error e.messageenddef destroydiff --git a/spec/requests/admin/themes_controller_spec.rb b/spec/requests/admin/themes_controller_spec.rbindex dc25e125138..c20b1284a0f 100644--- a/spec/requests/admin/themes_controller_spec.rb+++ b/spec/requests/admin/themes_controller_spec.rb@@ -311,7 +311,19 @@ describe Admin::ThemesController do# Database correcttheme.reloadexpect(theme.theme_translation_overrides.count).to eq(0)+ end++ it 'handles import errors on update' do+ theme.create_remote_theme!(remote_url: "https://example.com/repository")+ # RemoteTheme is extensively tested, and setting up the test scaffold is a large overhead+ # So use a stub here to test the controller+ RemoteTheme.any_instance.stubs(:update_from_remote).raises(RemoteTheme::ImportError.new("error message"))+ put "/admin/themes/#{theme.id}.json", params: {+ theme: { remote_update: true }+ }+ expect(response.status).to eq(422)+ expect(JSON.parse(response.body)["errors"].first).to eq("error message")endit 'returns the right error message' do