Skip to content
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

Hw add global exception handler #7

Merged
merged 4 commits into from
Sep 11, 2024
Merged

Conversation

ChabVlad
Copy link
Owner

No description provided.

validation annotations added to CreateBookRequestDto
Copy link

@Elena-Bruyako Elena-Bruyako left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comments

private String author;
@NotNull

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@NotNull
@NotBlank

.map(this::getErrorMessage)
.toList();
body.put("error", errors);
return new ResponseEntity<>(body, headers, status);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return new ResponseEntity<>(body, headers, status);
return new ResponseEntity<>(body, headers, HttpStatus.BAD_REQUEST);

@Constraint(validatedBy = UniqueValidation.class)
@Target({ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface Unique {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove redundant validatot
you have unique constraint in Book entity
If you would like to check isbn, it's better to use regexp pattern

pattern format isbn added
Copy link

@Elena-Bruyako Elena-Bruyako left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comments

@@ -6,4 +6,6 @@

public interface BookRepository extends JpaRepository<Book, Long>, JpaSpecificationExecutor<Book> {

boolean existsByIsbn(String isbn);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove


@ControllerAdvice
public class CustomGlobalExceptionHandler extends ResponseEntityExceptionHandler {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

@ChabVlad ChabVlad merged commit fc90c88 into main Sep 11, 2024
2 checks passed
@ChabVlad ChabVlad deleted the hw_add_globalExceptionHandler branch September 11, 2024 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants