MCPcopy Index your code
hub / github.com/OpenTSDB/opentsdb / formatErrorV1

Method formatErrorV1

src/tsd/HttpSerializer.java:853–885  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 5

runMethod · 0.80
callMethod · 0.80
callMethod · 0.80
internalErrorMethod · 0.80
badRequestMethod · 0.80

Calls 11

escapeJsonMethod · 0.95
isEmptyMethod · 0.80
showStackTraceMethod · 0.80
getCharsetMethod · 0.80
getMessageMethod · 0.65
getStatusMethod · 0.65
getQueryStringParamMethod · 0.45
appendMethod · 0.45
toStringMethod · 0.45
getDetailsMethod · 0.45
getBytesMethod · 0.45

Tested by

no test coverage detected