public void writeError(ODataServerError error) {
   try {
     writeContent(this.serializer.error(error).getContent(), error.getStatusCode(), true);
   } catch (SerializerException e) {
     writeServerError(true);
   }
 }
Example #2
0
  @Override
  public void processError(ODataServerError error, ErrorResponse response) {
    int logLevel = error.getStatusCode() >= 500 ? MessageLevel.ERROR : MessageLevel.WARNING;
    Throwable ex = getRoot(error.getException());
    // many exceptions in TeiidServiceHandler default as INTERNAL_SERVER_ERROR
    // so we make a better check for codes here
    if (ex instanceof TeiidNotImplementedException) {
      error.setException((TeiidNotImplementedException) ex);
      error.setCode(((TeiidNotImplementedException) ex).getCode());
      error.setStatusCode(501);
      logLevel = MessageLevel.DETAIL;
    } else if (ex instanceof TeiidProcessingException) {
      error.setException((TeiidProcessingException) ex);
      error.setCode(((TeiidProcessingException) ex).getCode());
      error.setStatusCode(400);
      logLevel = MessageLevel.WARNING;
    } else if (ex instanceof TeiidException) {
      error.setException((TeiidException) ex);
      error.setCode(((TeiidException) ex).getCode());
      error.setStatusCode(500);
      logLevel = MessageLevel.ERROR;
    } else if (ex instanceof TeiidRuntimeException) {
      error.setException((TeiidRuntimeException) ex);
      error.setCode(((TeiidRuntimeException) ex).getCode());
      error.setStatusCode(500);
      logLevel = MessageLevel.ERROR;
    }

    if (ex != error.getException() && ex.getMessage() != null) {
      if (LogManager.isMessageToBeRecorded(LogConstants.CTX_ODATA, MessageLevel.DETAIL)
          || logLevel <= MessageLevel.ERROR) {
        LogManager.log(
            logLevel,
            LogConstants.CTX_ODATA,
            error.getException(),
            ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16050, error.getMessage(), ex.getMessage()));
      } else {
        LogManager.log(
            logLevel,
            LogConstants.CTX_DQP,
            ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16051, error.getMessage(), ex.getMessage()));
      }
    } else {
      if (LogManager.isMessageToBeRecorded(LogConstants.CTX_ODATA, MessageLevel.DETAIL)
          || logLevel <= MessageLevel.ERROR) {
        LogManager.log(
            logLevel,
            LogConstants.CTX_ODATA,
            error.getException(),
            ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16052, error.getMessage()));
      } else {
        LogManager.log(
            logLevel,
            LogConstants.CTX_DQP,
            ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16053, error.getMessage()));
      }
    }
    response.writeError(error);
  }