aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/dev/submelon/pantry/ErrorResponse.java
diff options
context:
space:
mode:
authorKevin J Hoerr <khoerr@ksmpartners.com>2022-01-27 14:12:29 -0500
committerKevin J Hoerr <khoerr@ksmpartners.com>2022-01-27 14:12:29 -0500
commit615c8a0fc8d2b35da7df90115456d33444104c41 (patch)
treeaeab4261b4edaf63905bd008ce6992b0d2490916 /src/main/java/dev/submelon/pantry/ErrorResponse.java
parent8d8d8cdd639591c0c4c49b355db1152e310c22d6 (diff)
downloadpantry-615c8a0fc8d2b35da7df90115456d33444104c41.tar.gz
pantry-615c8a0fc8d2b35da7df90115456d33444104c41.tar.bz2
pantry-615c8a0fc8d2b35da7df90115456d33444104c41.zip
Add error handling
Diffstat (limited to 'src/main/java/dev/submelon/pantry/ErrorResponse.java')
-rw-r--r--src/main/java/dev/submelon/pantry/ErrorResponse.java58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/main/java/dev/submelon/pantry/ErrorResponse.java b/src/main/java/dev/submelon/pantry/ErrorResponse.java
new file mode 100644
index 0000000..c5b1dbe
--- /dev/null
+++ b/src/main/java/dev/submelon/pantry/ErrorResponse.java
@@ -0,0 +1,58 @@
+package dev.submelon.pantry;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Getter;
+import lombok.Setter;
+import org.springframework.http.HttpStatus;
+import java.util.Date;
+
+@Getter
+@Setter
+public class ErrorResponse {
+ // customizing timestamp serialization format
+ @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy hh:mm:ss")
+ private Date timestamp;
+
+ private int code;
+
+ private String status;
+
+ private String message;
+
+ private String stackTrace;
+
+ private Object data;
+
+ public ErrorResponse() {
+ timestamp = new Date();
+ }
+
+ public ErrorResponse(HttpStatus httpStatus, String message) {
+ this();
+
+ this.code = httpStatus.value();
+ this.status = httpStatus.name();
+ this.message = message;
+ }
+
+ public ErrorResponse(
+ HttpStatus httpStatus,
+ String message,
+ String stackTrace
+ ) {
+ this(httpStatus, message);
+
+ this.stackTrace = stackTrace;
+ }
+
+ public ErrorResponse(
+ HttpStatus httpStatus,
+ String message,
+ String stackTrace,
+ Object data
+ ) {
+ this(httpStatus, message, stackTrace);
+
+ this.data = data;
+ }
+}