public ErrorEvent(final BaseException exception) { code = exception.getErrorCode(); message = exception.getMessage(); fatal = Severity.FATAL.equals(code.getSeverity()); }
public FormattedErrorCode format(Object... data) { return new FormattedErrorCode( new ErrorCode( errorId, formatStr(data), severity)); }
public BaseException(final ErrorCode errorCode) { super( errorCode.toString()); this.errorCode = errorCode; }
@Test public void testSet() { EventBus bus = mock(EventBus.class); ErrorBus.setErrorBus(bus); errorBus.post(this); verify(bus).post(this); }
@Before public void setup() { bus = new ErrorBus(); EventBus ebus = new EventBus(); ebus.register(this); ErrorBus.setErrorBus(ebus); }
private String name(ErrorCode c) { return prefix + ".error-" + c.getSeverity() + "-" + c.getErrorId(); }
@GET @Produces("text/plain") @Path("/fatal") public String fatal() { try { throw new InvalidStateException( Errors.SYSTEM_FAILURE.format("*eek*")); } catch (Exception e) { e.printStackTrace(); } return "unrecoverable fatal error"; }
@Subscribe public void error(ErrorCode c) { registry.meter(prefix + ".errors") .mark(); registry.counter(prefix + ".errors-count") .inc(); if (this.configuration.isErrorsByCode()) { registry.meter(name(c)) .mark(); registry.counter(name(c) + "-count") .inc(); } if (this.configuration.isErrorsByType()) { registry.meter(prefix + ".error-severity-" + c.getSeverity() .name()) .mark(); registry.counter(prefix + ".error-severity-" + c.getSeverity() .name() + "-count") .inc(); } }
@PostConstruct public void register() { errorBus.register(this); ErrorBus.setErrorBus(errorBus); }
public static ErrorCode low(final int errorId, final String message) { return new ErrorCode( errorId, message, Severity.LOW); }
@Test public void testNotSet() { errorBus.post(this); }
@GET @Produces("text/plain") @Path("/error") public String error() { try { throw new InvalidStateException( Errors.QUERY_FAILURE.format("*eek*")); } catch (Exception e) { e.printStackTrace(); } return "error"; }
public static ErrorCode critical(final int errorId, final String message) { return new ErrorCode( errorId, message, Severity.CRITICAL); }
public BaseException(final ErrorCode errorCode, final Throwable cause) { super( errorCode.toString(), cause); this.errorCode = errorCode; }
@Test public void testEventErrorSuscriber() { new InvalidStateException( Errors.QUERY_FAILURE.format()); assertTrue(eventTriggered); }
public static ErrorCode medium(final int errorId, final String message) { return new ErrorCode( errorId, message, Severity.MEDIUM); }
public static ErrorCode high(final int errorId, final String message) { return new ErrorCode( errorId, message, Severity.HIGH); }
public static ErrorCode error(final int errorId, final String message, final Severity severity) { return new ErrorCode( errorId, message, severity); }