Java Code Examples for org.apache.solr.common.SolrException.ErrorCode#getErrorCode()

The following examples show how to use org.apache.solr.common.SolrException.ErrorCode#getErrorCode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ZookeeperInfoHandler.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
void writeError(int code, String msg) throws IOException {
  throw new SolrException(ErrorCode.getErrorCode(code), msg);
  /*response.setStatus(code);

  CharArr chars = new CharArr();
  JSONWriter w = new JSONWriter(chars, 2);
  w.startObject();
  w.indent();
  w.writeString("status");
  w.writeNameSeparator();
  w.write(code);
  w.writeValueSeparator();
  w.indent();
  w.writeString("error");
  w.writeNameSeparator();
  w.writeString(msg);
  w.endObject();

  out.write(chars.toString());*/
}
 
Example 2
Source File: SolrExceptionTranslator.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Override
public DataAccessException translateExceptionIfPossible(RuntimeException ex) {
	if (ex.getCause() instanceof SolrServerException) {
		SolrServerException solrServerException = (SolrServerException) ex.getCause();
		if (solrServerException.getCause() instanceof SolrException) {
			SolrException solrException = (SolrException) solrServerException.getCause();
			// solr 4.x moved ParseExecption from
			// org.apache.lucene.queryParser to
			// org.apache.lucene.queryparser.classic
			// therefore compare ShortClassName instead of using instanceof
			// expression
			if (solrException.getCause() != null && ClassUtils.getShortName(solrException.getCause().getClass())
					.equalsIgnoreCase("ParseException")) {
				return new InvalidDataAccessApiUsageException((solrException.getCause()).getMessage(),
						solrException.getCause());
			} else {
				ErrorCode errorCode = ErrorCode.getErrorCode(solrException.code());
				switch (errorCode) {
				case NOT_FOUND:
				case SERVICE_UNAVAILABLE:
				case SERVER_ERROR:
					return new DataAccessResourceFailureException(solrException.getMessage(), solrException);
				case FORBIDDEN:
				case UNAUTHORIZED:
					return new PermissionDeniedDataAccessException(solrException.getMessage(), solrException);
				case BAD_REQUEST:
					return new InvalidDataAccessApiUsageException(solrException.getMessage(), solrException);
				case UNKNOWN:
					return new UncategorizedSolrException(solrException.getMessage(), solrException);
				default:
					break;
				}
			}
		} else if (solrServerException.getCause() instanceof ConnectException) {
			return new DataAccessResourceFailureException(solrServerException.getCause().getMessage(),
					solrServerException.getCause());
		}
	}
	return null;
}
 
Example 3
Source File: SolrResponse.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public Exception getException() {
  @SuppressWarnings({"rawtypes"})
  NamedList exp = (NamedList) getResponse().get("exception");
  if (exp == null) {
    return null;
  }
  Integer rspCode = (Integer) exp.get("rspCode");
  ErrorCode errorCode = rspCode != null && rspCode != -1 ? ErrorCode.getErrorCode(rspCode) : ErrorCode.SERVER_ERROR;
  return new SolrException(errorCode, (String)exp.get("msg"));
}