From 7e910f98b4baf29921e2c14513189ca03361fa3d Mon Sep 17 00:00:00 2001 From: Rainnny7 Date: Sat, 6 Apr 2024 14:44:14 -0400 Subject: [PATCH] Custom error response --- .../me/braydon/mc/model/ErrorResponse.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/main/java/me/braydon/mc/model/ErrorResponse.java diff --git a/src/main/java/me/braydon/mc/model/ErrorResponse.java b/src/main/java/me/braydon/mc/model/ErrorResponse.java new file mode 100644 index 0000000..57a2677 --- /dev/null +++ b/src/main/java/me/braydon/mc/model/ErrorResponse.java @@ -0,0 +1,37 @@ +package me.braydon.mc.model; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.*; +import org.springframework.http.HttpStatus; + +import java.util.Date; + +/** + * A response representing an error. + * + * @author Braydon + */ +@NoArgsConstructor @Setter @Getter @ToString +public final class ErrorResponse { + /** + * The status code of this error. + */ + @NonNull private HttpStatus status; + + /** + * The message of this error. + */ + @NonNull private String message; + + /** + * The timestamp this error occurred. + */ + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy hh:mm:ss") + private Date timestamp; + + public ErrorResponse(@NonNull HttpStatus status, @NonNull String message) { + this.status = status; + this.message = message; + timestamp = new Date(); + } +} \ No newline at end of file