From b17619f92822255d3eb72a4cab6e71d50880b1df Mon Sep 17 00:00:00 2001 From: kyle-ssg Date: Fri, 31 May 2024 11:39:02 +0100 Subject: [PATCH 1/4] Environment creating state --- frontend/common/stores/project-store.js | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/common/stores/project-store.js b/frontend/common/stores/project-store.js index 10bea02bd1bd..1d55a1c48a48 100644 --- a/frontend/common/stores/project-store.js +++ b/frontend/common/stores/project-store.js @@ -15,6 +15,7 @@ const data = require('../data/base/_data') const controller = { createEnv: (name, projectId, cloneId, description) => { API.trackEvent(Constants.events.CREATE_ENVIRONMENT) + store.saving() const req = cloneId ? data.post(`${Project.api}environments/${cloneId}/clone/`, { description, From 04b239c24933d575dba15c35edb85b67a4910548 Mon Sep 17 00:00:00 2001 From: kyle-ssg Date: Mon, 3 Jun 2024 17:41:14 +0100 Subject: [PATCH 2/4] fix error handling of create environment --- frontend/common/stores/project-store.js | 68 +++++++++++++------------ 1 file changed, 36 insertions(+), 32 deletions(-) diff --git a/frontend/common/stores/project-store.js b/frontend/common/stores/project-store.js index 1d55a1c48a48..f2234dfb36f4 100644 --- a/frontend/common/stores/project-store.js +++ b/frontend/common/stores/project-store.js @@ -27,39 +27,43 @@ const controller = { project: projectId, }) - req.then((res) => - data - .put(`${Project.api}environments/${res.api_key}/`, { - description, - name, - project: projectId, - }) - .then((res) => - data - .post( - `${Project.api}environments/${ - res.api_key - }/${Utils.getIdentitiesEndpoint()}/`, - { - environment: res.api_key, - identifier: `${name.toLowerCase()}_user_123456`, - }, - ) - .then(() => { - store.savedEnv = res - if (store.model && store.model.environments) { - store.model.environments = store.model.environments.concat([ - res, - ]) - } - store.saved() - getStore().dispatch( - environmentService.util.invalidateTags(['Environment']), + req + .then((res) => + data + .put(`${Project.api}environments/${res.api_key}/`, { + description, + name, + project: projectId, + }) + .then((res) => + data + .post( + `${Project.api}environments/${ + res.api_key + }/${Utils.getIdentitiesEndpoint()}/`, + { + environment: res.api_key, + identifier: `${name.toLowerCase()}_user_123456`, + }, ) - AppActions.refreshOrganisation() - }), - ), - ) + .then(() => { + store.savedEnv = res + if (store.model && store.model.environments) { + store.model.environments = store.model.environments.concat([ + res, + ]) + } + store.saved() + getStore().dispatch( + environmentService.util.invalidateTags(['Environment']), + ) + AppActions.refreshOrganisation() + }), + ), + ) + .catch((e) => { + API.ajaxHandler(store, e) + }) }, deleteEnv: (env) => { From e5036f3398f1669645232947f87eaad8fa7a4205 Mon Sep 17 00:00:00 2001 From: kyle-ssg Date: Tue, 4 Jun 2024 15:01:17 +0100 Subject: [PATCH 3/4] fix ajaxhandler --- frontend/web/project/api.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/frontend/web/project/api.js b/frontend/web/project/api.js index 665f118fd2f3..1f33a17a6bf4 100644 --- a/frontend/web/project/api.js +++ b/frontend/web/project/api.js @@ -17,7 +17,13 @@ global.API = { // Catch coding errors that end up here if (res instanceof Error) { - console.log(res) + console.error(res) + store.error = res + store.goneABitWest() + return + } else if (res.data) { + store.error = res.data + store.goneABitWest() return } From 4bb5de42a219dfe34bc5c5e7ffed09194cab11fb Mon Sep 17 00:00:00 2001 From: kyle-ssg Date: Wed, 5 Jun 2024 11:08:10 +0100 Subject: [PATCH 4/4] Fix error parsing for project provider --- frontend/common/providers/ProjectProvider.js | 1 + frontend/web/components/ErrorMessage.js | 2 +- frontend/web/components/pages/CreateEnvironmentPage.js | 6 +++++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/frontend/common/providers/ProjectProvider.js b/frontend/common/providers/ProjectProvider.js index f427a268ebfc..2f29fd73b75c 100644 --- a/frontend/common/providers/ProjectProvider.js +++ b/frontend/common/providers/ProjectProvider.js @@ -24,6 +24,7 @@ const ProjectProvider = class extends React.Component { this.setState( Object.assign( { + error: ProjectStore.error, isLoading: ProjectStore.isLoading, isSaving: ProjectStore.isSaving, }, diff --git a/frontend/web/components/ErrorMessage.js b/frontend/web/components/ErrorMessage.js index b1290f482a67..50c6e0f9e11b 100644 --- a/frontend/web/components/ErrorMessage.js +++ b/frontend/web/components/ErrorMessage.js @@ -12,7 +12,7 @@ export default class ErrorMessage extends PureComponent { const errorMessageClassName = `alert alert-danger ${ this.props.errorMessageClass || 'flex-1 align-items-center' }` - const error = this.props.error?.data || this.props.error + const error = this.props.error?.data || this.props.error?.message || this.props.error return this.props.error ? (
)} + {error && ( + + + + )}
- {error && }
{permission ? (