Format a bad request exception, indicating an invalid request from the user WARNING: If overriding, make sure this method catches all errors and returns a byte array with a simple string error at the minimum @param exception The exception to format @return A standard JSON error
(final BadRequestException exception)
| 851 | * @return A standard JSON error |
| 852 | */ |
| 853 | public ChannelBuffer formatErrorV1(final BadRequestException exception) { |
| 854 | StringBuilder output = |
| 855 | new StringBuilder(exception.getMessage().length() * 2); |
| 856 | final String jsonp = query.getQueryStringParam("jsonp"); |
| 857 | if (jsonp != null && !jsonp.isEmpty()) { |
| 858 | output.append(query.getQueryStringParam("jsonp") + "("); |
| 859 | } |
| 860 | output.append("{\"error\":{\"code\":"); |
| 861 | output.append(exception.getStatus().getCode()); |
| 862 | final StringBuilder msg = new StringBuilder(exception.getMessage().length()); |
| 863 | HttpQuery.escapeJson(exception.getMessage(), msg); |
| 864 | output.append(",\"message\":\"").append(msg.toString()).append("\""); |
| 865 | if (!exception.getDetails().isEmpty()) { |
| 866 | final StringBuilder details = new StringBuilder( |
| 867 | exception.getDetails().length()); |
| 868 | HttpQuery.escapeJson(exception.getDetails(), details); |
| 869 | output.append(",\"details\":\"").append(details.toString()).append("\""); |
| 870 | } |
| 871 | if (query.showStackTrace()) { |
| 872 | ThrowableProxy tp = new ThrowableProxy(exception); |
| 873 | tp.calculatePackagingData(); |
| 874 | final String pretty_exc = ThrowableProxyUtil.asString(tp); |
| 875 | final StringBuilder trace = new StringBuilder(pretty_exc.length()); |
| 876 | HttpQuery.escapeJson(pretty_exc, trace); |
| 877 | output.append(",\"trace\":\"").append(trace.toString()).append("\""); |
| 878 | } |
| 879 | output.append("}}"); |
| 880 | if (jsonp != null && !jsonp.isEmpty()) { |
| 881 | output.append(")"); |
| 882 | } |
| 883 | return ChannelBuffers.copiedBuffer( |
| 884 | output.toString().getBytes(this.query.getCharset())); |
| 885 | } |
| 886 | |
| 887 | /** |
| 888 | * Format an internal error exception that was caused by the system |
no test coverage detected