-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from Wassim-Rached/staging
Staging v0.1.5
- Loading branch information
Showing
57 changed files
with
2,670 additions
and
604 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/java/org/wa55death405/quizhub/advices/ProductionExceptionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.wa55death405.quizhub.advices; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ControllerAdvice; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.wa55death405.quizhub.dto.StandardApiResponse; | ||
import org.wa55death405.quizhub.entities.ErrorLog; | ||
import org.wa55death405.quizhub.enums.StandardApiStatus; | ||
import org.wa55death405.quizhub.exceptions.IrregularBehaviorException; | ||
import org.wa55death405.quizhub.repositories.ErrorLogRepository; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@ControllerAdvice | ||
@Profile({"prod"}) | ||
@RequiredArgsConstructor | ||
public class ProductionExceptionHandler { | ||
|
||
private final ErrorLogRepository errorLogRepository; | ||
|
||
@ExceptionHandler(IrregularBehaviorException.class) | ||
public ResponseEntity<StandardApiResponse<Void>> handleIrregularBehaviorException(IrregularBehaviorException e) { | ||
ErrorLog errorLog = ErrorLog.builder() | ||
.exceptionMessage(e.getMessage()) | ||
.stackTrace(ErrorLog.getStackTraceAsString(e)) | ||
.build(); | ||
errorLogRepository.save(errorLog); | ||
return new ResponseEntity<>(new StandardApiResponse<>(StandardApiStatus.FAILURE, "Something Irregular just happened"), HttpStatus.INTERNAL_SERVER_ERROR); | ||
} | ||
|
||
@ExceptionHandler(Exception.class) | ||
public ResponseEntity<StandardApiResponse<Void>> handleException(Exception e) { | ||
ErrorLog errorLog = ErrorLog.builder() | ||
.exceptionMessage(e.getMessage()) | ||
.stackTrace(ErrorLog.getStackTraceAsString(e)) | ||
.timestamp(LocalDateTime.now()) | ||
.build(); | ||
errorLogRepository.save(errorLog); | ||
return new ResponseEntity<>(new StandardApiResponse<>(StandardApiStatus.FAILURE, "Something Went Wrong!"), HttpStatus.INTERNAL_SERVER_ERROR); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.