From f6573233cee0239e393242f3229201a2a4b36e3e Mon Sep 17 00:00:00 2001 From: Alessio Biancalana Date: Mon, 9 Sep 2024 10:44:02 +0200 Subject: [PATCH] Fix SUSE Manager settings CTA not showing up (#2952) --- assets/js/state/sagas/softwareUpdates.js | 8 ++++---- assets/js/state/sagas/softwareUpdates.test.js | 12 ++++++------ lib/trento_web/views/error_view.ex | 11 +++++++++++ .../controllers/v1/settings_controller_test.exs | 2 +- .../controllers/v1/suse_manager_controller_test.exs | 2 +- 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/assets/js/state/sagas/softwareUpdates.js b/assets/js/state/sagas/softwareUpdates.js index a405c459a1..5b598d25b3 100644 --- a/assets/js/state/sagas/softwareUpdates.js +++ b/assets/js/state/sagas/softwareUpdates.js @@ -30,10 +30,10 @@ export function* fetchSoftwareUpdates({ payload: hostID }) { const errorCode = get(error, ['response', 'status']); const errors = get(error, ['response', 'data', 'errors'], []); const suma_unauthorized = errors.some( - ({ detail }) => detail === 'SUSE Manager authentication error.' + ({ detail }) => detail === 'SUSE Manager settings not configured.' ); - if (errorCode === 422 && suma_unauthorized) { + if (errorCode === 404 && suma_unauthorized) { yield put(setSettingsNotConfigured()); } else { yield put(setSettingsConfigured()); @@ -70,10 +70,10 @@ export function* fetchUpgradablePackagesPatches({ const errors = get(error, ['response', 'data', 'errors'], []); const suma_unauthorized = errors.some( - ({ detail }) => detail === 'SUSE Manager authentication error.' + ({ detail }) => detail === 'SUSE Manager settings not configured.' ); - if (errorCode === 422 && suma_unauthorized) { + if (errorCode === 404 && suma_unauthorized) { yield put(setSettingsNotConfigured()); } else { yield put(setSettingsConfigured()); diff --git a/assets/js/state/sagas/softwareUpdates.test.js b/assets/js/state/sagas/softwareUpdates.test.js index cf4d7311b3..724f10c98c 100644 --- a/assets/js/state/sagas/softwareUpdates.test.js +++ b/assets/js/state/sagas/softwareUpdates.test.js @@ -120,15 +120,15 @@ describe('Software Updates saga', () => { const errorBody = { errors: [ { - title: 'Unprocessable Entity', - detail: 'SUSE Manager authentication error.', + title: 'Not Found', + detail: 'SUSE Manager settings not configured.', }, ], }; axiosMock .onGet(`/api/v1/hosts/${hostID}/software_updates`) - .reply(422, errorBody); + .reply(404, errorBody); const dispatched = await recordSaga(fetchSoftwareUpdates, { payload: hostID, @@ -206,15 +206,15 @@ describe('Software Updates saga', () => { const errorBody = { errors: [ { - title: 'Unprocessable Entity', - detail: 'SUSE Manager authentication error.', + title: 'Not Found', + detail: 'SUSE Manager settings not configured.', }, ], }; axiosMock .onGet(`/api/v1/hosts/${hostID}/software_updates`) - .reply(422, errorBody); + .reply(404, errorBody); const dispatched = await recordSaga(fetchSoftwareUpdates, { payload: hostID, diff --git a/lib/trento_web/views/error_view.ex b/lib/trento_web/views/error_view.ex index 8763ec25ae..11ed420d18 100644 --- a/lib/trento_web/views/error_view.ex +++ b/lib/trento_web/views/error_view.ex @@ -34,6 +34,17 @@ defmodule TrentoWeb.ErrorView do } end + def render("404.json", %{reason: reason}) do + %{ + errors: [ + %{ + title: "Not Found", + detail: reason + } + ] + } + end + def render("404.json", _) do %{ errors: [ diff --git a/test/trento_web/controllers/v1/settings_controller_test.exs b/test/trento_web/controllers/v1/settings_controller_test.exs index bf8957fdab..33f9074c60 100644 --- a/test/trento_web/controllers/v1/settings_controller_test.exs +++ b/test/trento_web/controllers/v1/settings_controller_test.exs @@ -339,7 +339,7 @@ defmodule TrentoWeb.V1.SettingsControllerTest do assert %{ "errors" => [ - %{"detail" => "The requested resource cannot be found.", "title" => "Not Found"} + %{"detail" => "SUSE Manager settings not configured.", "title" => "Not Found"} ] } == resp end diff --git a/test/trento_web/controllers/v1/suse_manager_controller_test.exs b/test/trento_web/controllers/v1/suse_manager_controller_test.exs index 4e9d57f0cb..116fc5593f 100644 --- a/test/trento_web/controllers/v1/suse_manager_controller_test.exs +++ b/test/trento_web/controllers/v1/suse_manager_controller_test.exs @@ -69,7 +69,7 @@ defmodule TrentoWeb.V1.SUSEManagerControllerTest do assert %{ "errors" => [ - %{"detail" => "The requested resource cannot be found.", "title" => "Not Found"} + %{"detail" => "SUSE Manager settings not configured.", "title" => "Not Found"} ] } == resp end