In real life, we encountered 500 Internal Server Error unexpectedly from bookies, like ISN and Pinnacle.
We found why we got 500 from Pinnacle, a negative event id resulted in 500, once we correct the event id, everything went back to normal.
I was just wondering why the bookie doesn't respond with more friendly error message?
ISN's parameters consist of esoteric keys, much more difficult to debug, nevertheless, the most suspicious cause would be similar to Pinnacle's. I will dig it deeper.
I found Pinnacle's documentation says this:
So, I guess Pinnacle REST service set the HTTP status code as 500, and adds some information like 'Unexpected error', however, once Spring framework's Rest Template got the 500 status code, it translates 500 into a general message, "Internal Server Error". We lost original message due to Rest Template!!!
However, Spring Rest Template Code defies my guess:
/**
* This default implementation throws a {@link HttpClientErrorException} if the response status code
* is {@link org.springframework.http.HttpStatus.Series#CLIENT_ERROR}, a {@link HttpServerErrorException}
* if it is {@link org.springframework.http.HttpStatus.Series#SERVER_ERROR},
* and a {@link RestClientException} in other cases.
*/
public void handleError(ClientHttpResponse response) throws IOException {
HttpStatus statusCode = getHttpStatusCode(response);
switch (statusCode.series()) {
case CLIENT_ERROR:
throw new HttpClientErrorException(statusCode, response.getStatusText(),
response.getHeaders(), getResponseBody(response), getCharset(response));
case SERVER_ERROR:
throw new HttpServerErrorException(statusCode, response.getStatusText(),
response.getHeaders(), getResponseBody(response), getCharset(response));
default:
throw new RestClientException("Unknown status code [" + statusCode + "]");
}
}
Apart from the above code, another fact shows my guess is wrong, that is we frequently receives ISN error "400 Unknown Error", in org.springframework.http.HttpStatus, we can see
/**
* {@code 400 Bad Request}.
* @see <a href="http://tools.ietf.org/html/rfc2616#section-10.4.1">HTTP/1.1</a>
*/
BAD_REQUEST(400, "Bad Request"),
Another attempt: In JSP, when we encounter 500 error with browser, we often see tons of application exception information additionally, sometimes the stack trace is very useful for debugging, with Rest Template, how can we capture the stack trace? From R1 and R2, we can try this in log4j configuration:
<logger name="log4j.logger.httpclient.wire" additivity="false">
<level value="DEBUG" />
<appender-ref ref="xxxAppender" />
</logger>
or
log4j.logger.httpclient.wire=DEBUG
Reference:
1. http://stackoverflow.com/questions/7952154/spring-resttemplate-how-to-enable-full-debugging-logging-of-requests-responses
2. http://stackoverflow.com/questions/21402950/debug-resttemplate-post-request