コード例 #1
0
 private OrcidMessage getLegacy500OrcidEntity(Throwable e) {
   OrcidMessage entity = new OrcidMessage();
   entity.setMessageVersion(OrcidMessage.DEFAULT_VERSION);
   entity.setErrorDesc(
       new ErrorDesc(
           StringUtils.isNotBlank(e.getMessage())
               ? e.getMessage()
               : messageSource.getMessage(
                   "apiError.unknown.exception", null, localeManager.getLocale())));
   return entity;
 }
コード例 #2
0
  private OrcidError getOrcidError(int errorCode, int status, Throwable t) {
    Locale locale = localeManager.getLocale();
    OrcidError orcidError = new OrcidError();
    orcidError.setResponseCode(status);
    orcidError.setErrorCode(errorCode);
    orcidError.setMoreInfo(
        messageSource.getMessage("apiError." + errorCode + ".moreInfo", null, locale));
    Map<String, String> params = null;
    if (t instanceof ApplicationException) {
      params = ((ApplicationException) t).getParams();
    }
    // Returns an empty message if the key is not found
    String devMessage =
        messageSource.getMessage("apiError." + errorCode + ".developerMessage", null, "", locale);

    // Assign message from the exception
    if ("".equals(devMessage)) {
      devMessage = t.getClass().getCanonicalName();
      Throwable cause = t.getCause();
      String exceptionMessage = t.getLocalizedMessage();
      if (exceptionMessage != null) {
        devMessage += ": " + exceptionMessage;
      }

      if (cause != null) {
        String causeMessage = cause.getLocalizedMessage();
        if (causeMessage != null) {
          devMessage += " (" + causeMessage + ")";
        }
      }
      orcidError.setDeveloperMessage(devMessage);
    } else {
      orcidError.setDeveloperMessage(resolveMessage(devMessage, params));
    }

    orcidError.setUserMessage(
        resolveMessage(
            messageSource.getMessage("apiError." + errorCode + ".userMessage", null, locale),
            params));
    return orcidError;
  }