-
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.
- Loading branch information
Showing
5 changed files
with
107 additions
and
0 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
21 changes: 21 additions & 0 deletions
21
src/main/java/restful/app/resources/exception/ResourceExceptionHandler.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,21 @@ | ||
package restful.app.resources.exception; | ||
|
||
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 jakarta.servlet.http.HttpServletRequest; | ||
import restful.app.services.exception.ObjectNotFoundException; | ||
|
||
@ControllerAdvice | ||
public class ResourceExceptionHandler { | ||
|
||
@ExceptionHandler(ObjectNotFoundException.class) | ||
public ResponseEntity<StandardError> objectNotFound(ObjectNotFoundException e, HttpServletRequest request){ | ||
|
||
HttpStatus status = HttpStatus.NOT_FOUND; | ||
StandardError err = new StandardError(System.currentTimeMillis(), status.value(), "Not found", e.getMessage(), request.getRequestURI()); | ||
return ResponseEntity.status(status).body(err); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
src/main/java/restful/app/resources/exception/StandardError.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,64 @@ | ||
package restful.app.resources.exception; | ||
|
||
import java.io.Serializable; | ||
|
||
public class StandardError implements Serializable{ | ||
private Long timestamp; | ||
private Integer status; | ||
private String error; | ||
private String message; | ||
private String path; | ||
|
||
public StandardError(){ | ||
} | ||
|
||
public StandardError(Long timestamp, Integer status, String error, String message, String path) { | ||
this.timestamp = timestamp; | ||
this.status = status; | ||
this.error = error; | ||
this.message = message; | ||
this.path = path; | ||
} | ||
|
||
public Long getTimestamp() { | ||
return timestamp; | ||
} | ||
|
||
public void setTimestamp(Long timestamp) { | ||
this.timestamp = timestamp; | ||
} | ||
|
||
public Integer getStatus() { | ||
return status; | ||
} | ||
|
||
public void setStatus(Integer status) { | ||
this.status = status; | ||
} | ||
|
||
public String getError() { | ||
return error; | ||
} | ||
|
||
public void setError(String error) { | ||
this.error = error; | ||
} | ||
|
||
public String getMessage() { | ||
return message; | ||
} | ||
|
||
public void setMessage(String message) { | ||
this.message = message; | ||
} | ||
|
||
public String getPath() { | ||
return path; | ||
} | ||
|
||
public void setPath(String path) { | ||
this.path = path; | ||
} | ||
|
||
|
||
} |
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
8 changes: 8 additions & 0 deletions
8
src/main/java/restful/app/services/exception/ObjectNotFoundException.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,8 @@ | ||
package restful.app.services.exception; | ||
|
||
public class ObjectNotFoundException extends RuntimeException{ | ||
|
||
public ObjectNotFoundException(String msg){ | ||
super(msg); | ||
} | ||
} |