Skip to content

Commit

Permalink
feat: adding error exception to login
Browse files Browse the repository at this point in the history
  • Loading branch information
PedroVidalDev committed Jun 11, 2024
1 parent eb0f031 commit 69ec796
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.pedro.sphynx.application.dtos.message.MessageDTO;
import jakarta.persistence.EntityNotFoundException;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

Expand All @@ -24,4 +25,10 @@ public ResponseEntity noSuchElement(){
public ResponseEntity validation(Validation e){
return ResponseEntity.badRequest().body(new MessageDTO(400, e.getMessage(), null));
}

@ExceptionHandler(UsernameNotFoundException.class)
public ResponseEntity auth(UsernameNotFoundException e){
return ResponseEntity.status(401).body(new MessageDTO(401, "Usuario ou senha incorretos.", null));
}

}

0 comments on commit 69ec796

Please sign in to comment.