You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
1.9 KiB
73 lines
1.9 KiB
package app.entities.db;
|
|
|
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
|
|
import java.sql.ResultSet;
|
|
import java.sql.SQLException;
|
|
import java.time.Instant;
|
|
import java.util.Arrays;
|
|
import java.util.stream.Collectors;
|
|
|
|
public class ErrorDb {
|
|
private final Integer id;
|
|
private final Long timestamp;
|
|
private final String message;
|
|
private final String trace;
|
|
private final String query;
|
|
private Throwable e;
|
|
|
|
public ErrorDb(ResultSet rs) throws SQLException {
|
|
this.id = rs.getInt("id");
|
|
this.timestamp = rs.getTimestamp("err_timestamp").getTime();
|
|
this.message = rs.getString("err_message");
|
|
this.trace = rs.getString("err_trace");
|
|
this.query = rs.getString("err_query");
|
|
this.e = null;
|
|
}
|
|
|
|
public ErrorDb(Throwable e, String query) {
|
|
this.id = null;
|
|
this.timestamp = Instant.now().getEpochSecond();
|
|
this.message = e.toString();
|
|
this.trace = Arrays.stream(e.getStackTrace())
|
|
.map(StackTraceElement::toString)
|
|
.collect(Collectors.joining("\n"));
|
|
this.query = query;
|
|
this.e = e;
|
|
}
|
|
|
|
public static String Request2Query(HttpServletRequest request) {
|
|
if (request == null) return null;
|
|
|
|
StringBuilder str = new StringBuilder();
|
|
str.append(request.getMethod()).append(" ");
|
|
str.append(request.getRequestURI()).append("?").append(request.getQueryString());
|
|
return str.toString();
|
|
}
|
|
|
|
public Integer getId() {
|
|
return id;
|
|
}
|
|
|
|
public Long getTimestamp() {
|
|
return timestamp;
|
|
}
|
|
|
|
public String getMessage() {
|
|
return message;
|
|
}
|
|
|
|
public String getTrace() {
|
|
return trace;
|
|
}
|
|
|
|
public String getQuery() {
|
|
return query;
|
|
}
|
|
|
|
@JsonIgnore
|
|
public Throwable getE() {
|
|
return e;
|
|
}
|
|
}
|