-
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
1 parent
d3d20fb
commit 66ca635
Showing
5 changed files
with
109 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
24 changes: 24 additions & 0 deletions
24
...in/java/com/miguelaugusto/workshopmongo/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,24 @@ | ||
package com.miguelaugusto.workshopmongo.resources.exception; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
|
||
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 com.miguelaugusto.workshopmongo.services.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(), "Não encontrado", e.getMessage(), | ||
request.getRequestURI()); | ||
return ResponseEntity.status(status).body(err); | ||
} | ||
|
||
} |
59 changes: 59 additions & 0 deletions
59
src/main/java/com/miguelaugusto/workshopmongo/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,59 @@ | ||
package com.miguelaugusto.workshopmongo.resources.exception; | ||
|
||
import java.io.Serializable; | ||
|
||
public class StandardError implements Serializable{ | ||
|
||
private static final long serialVersionUID = 1L; | ||
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) { | ||
super(); | ||
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 getPath() { | ||
return path; | ||
} | ||
|
||
public void setPath(String path) { | ||
this.path = path; | ||
} | ||
|
||
|
||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/miguelaugusto/workshopmongo/services/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,11 @@ | ||
package com.miguelaugusto.workshopmongo.services; | ||
|
||
public class ObjectNotFoundException extends RuntimeException { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
public ObjectNotFoundException(String msg) { | ||
super(msg); | ||
} | ||
|
||
} |
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