-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dcd75fd
commit b249dd6
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
src/main/java/com/sitblueprint/admin/controller/exceptions/GlobalExceptionHandler.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,26 @@ | ||
package com.sitblueprint.admin.controller.exceptions; | ||
|
||
import org.hibernate.service.spi.ServiceException; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.context.request.WebRequest; | ||
|
||
import java.util.NoSuchElementException; | ||
|
||
public class GlobalExceptionHandler { | ||
@ExceptionHandler | ||
public ResponseEntity handleServiceException(ServiceException e, WebRequest request) { | ||
return new ResponseEntity(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); | ||
} | ||
|
||
@ExceptionHandler | ||
public ResponseEntity handleNoSuchElementException(NoSuchElementException e, WebRequest request) { | ||
return new ResponseEntity("Resource not found", HttpStatus.NOT_FOUND); | ||
} | ||
|
||
@ExceptionHandler(Exception.class) | ||
public ResponseEntity handleGenericException(Exception e, WebRequest request) { | ||
return new ResponseEntity("An unexpected error has occurred", HttpStatus.INTERNAL_SERVER_ERROR); | ||
} | ||
} |