com.xlrit.gears.base.exception.BaseException Maven / Gradle / Ivy
package com.xlrit.gears.base.exception;
import java.time.OffsetDateTime;
import de.huxhorn.sulky.ulid.ULID;
public abstract class BaseException extends RuntimeException {
private static final ULID ulid = new ULID();
private final String id = ulid.nextULID();
private final OffsetDateTime timestamp = OffsetDateTime.now();
protected BaseException(Throwable cause) {
super(getRootCause(cause).getMessage(), cause);
}
protected BaseException(String message, Throwable cause) {
super(message, cause);
}
protected BaseException(String message) {
super(message);
}
public String getId() {
return id;
}
public OffsetDateTime getTimestamp() {
return timestamp;
}
protected static Throwable getRootCause(Throwable throwable) {
while (throwable.getCause() != null)
throwable = throwable.getCause();
return throwable;
}
}