List of usage examples for com.google.api.client.googleapis.json GoogleJsonError parse
public static GoogleJsonError parse(JsonFactory jsonFactory, HttpResponse response) throws IOException
From source file:it.uniba.di.cdg.xcore.ui.service.Util.java
License:Apache License
/** * Extract the request error details from a HttpResponseException * @param e An HttpResponseException that contains error details * @return The String representation of all errors that caused the * HttpResponseException//from w w w .ja va 2s . c o m * @throws IOException when the response cannot be parsed or stringified */ public static String extractError(HttpResponseException e) throws IOException { if (!Json.CONTENT_TYPE.equals(e.getResponse().getContentType())) { return e.getResponse().parseAsString(); } GoogleJsonError errorResponse = GoogleJsonError.parse(JSON_FACTORY, e.getResponse()); StringBuilder errorReportBuilder = new StringBuilder(); errorReportBuilder.append(errorResponse.code); errorReportBuilder.append(" Error: "); errorReportBuilder.append(errorResponse.message); for (GoogleJsonError.ErrorInfo error : errorResponse.errors) { errorReportBuilder.append(JSON_FACTORY.toString(error)); errorReportBuilder.append(Strings.LINE_SEPARATOR); } return errorReportBuilder.toString(); }