Sends a 500 error page to the client. Handles responses from deprecated API calls as well as newer, versioned API calls @param cause The unexpected exception that caused this error.
(final Exception cause)
| 346 | * @param cause The unexpected exception that caused this error. |
| 347 | */ |
| 348 | @Override |
| 349 | public void internalError(final Exception cause) { |
| 350 | logError("Internal Server Error on " + request().getUri(), cause); |
| 351 | |
| 352 | if (this.api_version > 0) { |
| 353 | // always default to the latest version of the error formatter since we |
| 354 | // need to return something |
| 355 | switch (this.api_version) { |
| 356 | case 1: |
| 357 | default: |
| 358 | sendReply(HttpResponseStatus.INTERNAL_SERVER_ERROR, |
| 359 | serializer.formatErrorV1(cause)); |
| 360 | } |
| 361 | return; |
| 362 | } |
| 363 | |
| 364 | ThrowableProxy tp = new ThrowableProxy(cause); |
| 365 | tp.calculatePackagingData(); |
| 366 | final String pretty_exc = ThrowableProxyUtil.asString(tp); |
| 367 | tp = null; |
| 368 | if (hasQueryStringParam("json")) { |
| 369 | // 32 = 10 + some extra space as exceptions always have \t's to escape. |
| 370 | final StringBuilder buf = new StringBuilder(32 + pretty_exc.length()); |
| 371 | buf.append("{\"err\":\""); |
| 372 | HttpQuery.escapeJson(pretty_exc, buf); |
| 373 | buf.append("\"}"); |
| 374 | sendReply(HttpResponseStatus.INTERNAL_SERVER_ERROR, buf); |
| 375 | } else { |
| 376 | sendReply(HttpResponseStatus.INTERNAL_SERVER_ERROR, |
| 377 | makePage("Internal Server Error", "Houston, we have a problem", |
| 378 | "<blockquote>" |
| 379 | + "<h1>Internal Server Error</h1>" |
| 380 | + "Oops, sorry but your request failed due to a" |
| 381 | + " server error.<br/><br/>" |
| 382 | + "Please try again in 30 seconds.<pre>" |
| 383 | + pretty_exc |
| 384 | + "</pre></blockquote>")); |
| 385 | } |
| 386 | } |
| 387 | |
| 388 | /** |
| 389 | * Sends a 400 error page to the client. |