Unexpected 500 Internal Server Error from Bookie Rest Service

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:

pinnacle error codes

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


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值