Skip to content

Commit

Permalink
[backend/frontend] Fix http response messages
Browse files Browse the repository at this point in the history
  • Loading branch information
savacano28 committed Jan 2, 2025
1 parent 26d4c04 commit 48272e0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
5 changes: 4 additions & 1 deletion openbas-api/src/main/java/io/openbas/rest/user/UserApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<User> optionalUser = userRepository.findByEmailIgnoreCase(input.getLogin());
if (optionalUser.isPresent()) {
User user = optionalUser.get();
Expand Down Expand Up @@ -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}")
Expand Down
6 changes: 4 additions & 2 deletions openbas-front/src/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
Expand Down
3 changes: 3 additions & 0 deletions openbas-front/src/utils/Action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) => {
Expand Down
3 changes: 3 additions & 0 deletions openbas-front/src/utils/Localization.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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': '此平台尚未提供模拟功能',
Expand Down Expand Up @@ -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.',
},
Expand Down

0 comments on commit 48272e0

Please sign in to comment.