-
Notifications
You must be signed in to change notification settings - Fork 0
Add item requests and gateway #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
avfyodorov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Добрый день, Даша!
Хорошая работа, от меня всего пара уточнений.
| return Map.of("error validation", ex.getMessage()); | ||
| } | ||
|
|
||
| @ExceptionHandler(MethodArgumentNotValidException.class) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Вот тут есть один момент.
Теперь есть (должно быть) два обработчика ошибок: один - в модуле гейтвей, а второй - это сервер. И ошибки перехватываются и обрабатываются, соответственно, разные. Например, на сервере валидация по заданию не нужна( точнее почти не нужна), только на gateway, поэтому и bad request на сервере вроде бы как быть не должно. И наоборот, на gateway не должно быть ничего, имеющего отношение к серверу (not found). Проверьте, пожалуйста, ещё раз этот момент.
На сервере только та валидация входных данных , которая требует работы с БД.
А в остальном на сервере(во всех классах, где ранее была валидация) не должно быть валидации и ее не должно быть и в зависимостях в pom файле тоже.
Есть предложение ещё раз проверить и уточнить, где какие ошибки ловятся и обрабатываются.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Поменяла наименование этого обработчика а также код, который он выбрасывает на 500. Данное исключение пробрасывается когда в коде происходит ошибка, связанная с попыткой отправить в бд некорректные данные. В gateway добавила errorHandler с обработкой валидации.
| @GetMapping("/search") | ||
| public ResponseEntity<Object> searchItems(@RequestHeader("X-Sharer-User-Id") @Positive Long userId, | ||
| @RequestParam("text") @NotBlank String text) { | ||
| return client.searchItems(userId, text); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Лучше было бы прямо здесь проверить входной параметр text. И, если текст запроса пустой, или недопустимый, например, состоит из пробелов, то прямо отсюда и вернуть результат, не обращаться к серверу. Вернуть можно, например, пустую коллекцию.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Спасибо за замечание, исправила
avfyodorov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Добрый день!
Замечаний нет.
Работа принята.
No description provided.