aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/dev/submelon/pantry/ErrorResponse.java
blob: c5b1dbe459f9ea81da0885bda4c40e5d3f98ca69 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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;
    }
}