Skip to content

Commit

Permalink
FIX ITEM-460-modifier-le-libelle-dun-message-derreur :
Browse files Browse the repository at this point in the history
     - ajout d'une méthode handleFileCheckingFailures() dans RestResponseEntityExceptionHandler.java
     - ajout d'un constructeur dans ApiReturnError.java
  • Loading branch information
EryneKL committed Jan 22, 2025
1 parent e0a9255 commit df7f88e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
13 changes: 12 additions & 1 deletion web/src/main/java/fr/abes/item/exception/ApiReturnError.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,16 @@ private ApiReturnError() {
this.debugMessage = ex.getMessage();
}


ApiReturnError(String fileCheckingError, HttpStatus status, String message, Throwable ex) {
this();
if (ex.getMessage().contains("Le fichier dépasse la limite des")) {
this.status = status;
this.message = ex.getMessage();
this.debugMessage = ex.getMessage();
} else {
this.status = status;
this.message = message;
this.debugMessage = ex.getMessage();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,16 @@ public ResponseEntity<?> handleForbiddenFailures(Throwable t) {
@ExceptionHandler(BadCredentialsException.class)
public ResponseEntity<?> handleBadCredentials(Throwable t) { return buildResponseEntity(new ApiReturnError(HttpStatus.UNAUTHORIZED, t.getMessage(), t)); }

@ExceptionHandler({ IllegalArgumentException.class, FileCheckingException.class, FileTypeException.class})
@ExceptionHandler({ IllegalArgumentException.class, FileTypeException.class})
public ResponseEntity<?> handleMiscFailures(Throwable t) {
return buildResponseEntity(new ApiReturnError(HttpStatus.BAD_REQUEST, Constant.ERR_FILE_WRONGCONTENT, t));
}

@ExceptionHandler({ FileCheckingException.class })
public ResponseEntity<?> handleFileCheckingFailures(Throwable t) {
return buildResponseEntity(new ApiReturnError("fileCheckingError", HttpStatus.BAD_REQUEST, Constant.ERR_FILE_WRONGCONTENT, t));
}

@ExceptionHandler({ DemandeCheckingException.class })
public ResponseEntity<?> handleBadConditionsFailures(Throwable t) { return buildResponseEntity(new ApiReturnError(HttpStatus.PRECONDITION_FAILED, t.getMessage(), t));}

Expand Down

0 comments on commit df7f88e

Please # to comment.