From 48272e09bdc7c2ecd044cd0724b015cfc3b409bb Mon Sep 17 00:00:00 2001 From: Stephanya Casanova Date: Thu, 2 Jan 2025 11:02:35 +0100 Subject: [PATCH] [backend/frontend] Fix http response messages --- openbas-api/src/main/java/io/openbas/rest/user/UserApi.java | 5 ++++- openbas-front/src/network.js | 6 ++++-- openbas-front/src/utils/Action.ts | 3 +++ openbas-front/src/utils/Localization.js | 3 +++ 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/openbas-api/src/main/java/io/openbas/rest/user/UserApi.java b/openbas-api/src/main/java/io/openbas/rest/user/UserApi.java index 40ea1688fd..47422137d7 100644 --- a/openbas-api/src/main/java/io/openbas/rest/user/UserApi.java +++ b/openbas-api/src/main/java/io/openbas/rest/user/UserApi.java @@ -33,6 +33,7 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.domain.Specification; +import org.springframework.http.ResponseEntity; import org.springframework.security.access.AccessDeniedException; import org.springframework.security.access.annotation.Secured; import org.springframework.security.authentication.BadCredentialsException; @@ -87,7 +88,7 @@ public User login(@Valid @RequestBody LoginUserInput input) { } @PostMapping("/api/reset") - public void passwordReset(@Valid @RequestBody ResetUserInput input) { + public ResponseEntity passwordReset(@Valid @RequestBody ResetUserInput input) { Optional optionalUser = userRepository.findByEmailIgnoreCase(input.getLogin()); if (optionalUser.isPresent()) { User user = optionalUser.get(); @@ -116,7 +117,9 @@ public void passwordReset(@Valid @RequestBody ResetUserInput input) { } // Store in memory reset token resetTokenMap.put(resetToken, user.getId()); + return ResponseEntity.ok().build(); } + return ResponseEntity.badRequest().build(); } @PostMapping("/api/reset/{token}") diff --git a/openbas-front/src/network.js b/openbas-front/src/network.js index b33f3b904b..a0daef7881 100644 --- a/openbas-front/src/network.js +++ b/openbas-front/src/network.js @@ -9,8 +9,10 @@ export const api = (schema) => { // Intercept to apply schema and test unauthorized users instance.interceptors.response.use( (response) => { - if (schema) { - response.data = normalize(response.data, schema); + if (response.data && schema) { + if (typeof response.data === 'object') { + response.data = normalize(response.data, schema); + } } return response; }, diff --git a/openbas-front/src/utils/Action.ts b/openbas-front/src/utils/Action.ts index 370235e3c3..93c7bf79f3 100644 --- a/openbas-front/src/utils/Action.ts +++ b/openbas-front/src/utils/Action.ts @@ -50,6 +50,8 @@ const notifyError = (error: AxiosError) => { // Do not notify the user, as a 401 error will already trigger a disconnection, as 404 already handle inside the app } else if (error.status === 409) { MESSAGING$.notifyError(intl.formatMessage({ id: 'The element already exists' })); + } else if (error.status === 400) { + MESSAGING$.notifyError(intl.formatMessage({ id: 'Bad request' })); } else if (error.status === 500) { MESSAGING$.notifyError(intl.formatMessage({ id: 'Internal error' })); } else if (error.message) { @@ -166,6 +168,7 @@ export const postReferential = (schema: Schema | null, uri: string, data: unknow .post(buildUri(uri), data) .then((response) => { dispatch({ type: Constants.DATA_FETCH_SUCCESS, payload: response.data }); + notifySuccess('The element has been successfully updated'); return response.data; }) .catch((error) => { diff --git a/openbas-front/src/utils/Localization.js b/openbas-front/src/utils/Localization.js index 43aba47866..cb1ac52714 100644 --- a/openbas-front/src/utils/Localization.js +++ b/openbas-front/src/utils/Localization.js @@ -1422,6 +1422,7 @@ const i18n = { 'Childrens': 'Enfants', 'Interactive view': 'Vue interactive', 'Execution successful': 'Exécution réussie', + 'Bad request': 'Mauvaise requête', 'Internal error': 'Erreur interne', 'The element has been successfully updated': 'L\'élément a été mis à jour avec succès', 'The element has been successfully deleted': 'L\'élément a été supprimé avec succès', @@ -2806,6 +2807,7 @@ const i18n = { 'Execution successful': '执行成功', 'The element has been successfully updated': '元素已成功更新', 'The element has been successfully deleted': '元素已成功删除', + 'Bad request': '错误的请求', 'Internal error': '内部错误 ', 'No data to display': '没有可显示的数据', 'No simulation in this platform yet': '此平台尚未提供模拟功能', @@ -2981,6 +2983,7 @@ const i18n = { 'Do you want to launch this atomic testing: {title}?': 'Do you want to launch this atomic testing: {title}?', 'Do you want to relaunch this atomic testing: {title}?': 'Do you want to relaunch this atomic testing: {title}?', 'The element already exists': 'The element already exists', + 'Bad request': 'Bad request', 'Internal error': 'Internal error', 'Something went wrong. Please refresh the page or try again later.': 'Something went wrong. Please refresh the page or try again later.', },