use of okhttp3.Response in project android-oss by kickstarter.
the class ApiExceptionFactory method badRequestException.
@NonNull
public static ApiException badRequestException() {
final ErrorEnvelope envelope = ErrorEnvelope.builder().errorMessages(Collections.singletonList("bad request")).httpCode(400).build();
final ResponseBody body = ResponseBody.create(null, "");
final retrofit2.Response<Observable<User>> response = retrofit2.Response.error(400, body);
return new ApiException(envelope, response);
}
use of okhttp3.Response in project android-oss by kickstarter.
the class ApiExceptionFactory method tfaRequired.
@NonNull
public static ApiException tfaRequired() {
final ErrorEnvelope envelope = ErrorEnvelope.builder().ksrCode(ErrorEnvelope.TFA_REQUIRED).httpCode(403).errorMessages(Collections.singletonList("Two-factor authentication required.")).build();
final ResponseBody body = ResponseBody.create(null, new Gson().toJson(envelope));
final retrofit2.Response<Observable<User>> response = retrofit2.Response.error(envelope.httpCode(), body);
return new ApiException(envelope, response);
}
use of okhttp3.Response in project android-oss by kickstarter.
the class ApiExceptionFactory method tfaFailed.
@NonNull
public static ApiException tfaFailed() {
final ErrorEnvelope envelope = ErrorEnvelope.builder().ksrCode(ErrorEnvelope.TFA_FAILED).httpCode(400).build();
final ResponseBody body = ResponseBody.create(null, new Gson().toJson(envelope));
final retrofit2.Response<Observable<User>> response = retrofit2.Response.error(envelope.httpCode(), body);
return new ApiException(envelope, response);
}
use of okhttp3.Response in project android-oss by kickstarter.
the class ApiExceptionFactory method apiError.
@NonNull
public static ApiException apiError(@NonNull final ErrorEnvelope errorEnvelope) {
final ResponseBody body = ResponseBody.create(null, new Gson().toJson(errorEnvelope));
final retrofit2.Response<Observable<User>> response = retrofit2.Response.error(errorEnvelope.httpCode(), body);
return new ApiException(errorEnvelope, response);
}
use of okhttp3.Response in project okhttputils by hongyangAndroid.
the class LoggerInterceptor method logForResponse.
private Response logForResponse(Response response) {
try {
//===>response log
Log.e(tag, "========response'log=======");
Response.Builder builder = response.newBuilder();
Response clone = builder.build();
Log.e(tag, "url : " + clone.request().url());
Log.e(tag, "code : " + clone.code());
Log.e(tag, "protocol : " + clone.protocol());
if (!TextUtils.isEmpty(clone.message()))
Log.e(tag, "message : " + clone.message());
if (showResponse) {
ResponseBody body = clone.body();
if (body != null) {
MediaType mediaType = body.contentType();
if (mediaType != null) {
Log.e(tag, "responseBody's contentType : " + mediaType.toString());
if (isText(mediaType)) {
String resp = body.string();
Log.e(tag, "responseBody's content : " + resp);
body = ResponseBody.create(mediaType, resp);
return response.newBuilder().body(body).build();
} else {
Log.e(tag, "responseBody's content : " + " maybe [file part] , too large too print , ignored!");
}
}
}
}
Log.e(tag, "========response'log=======end");
} catch (Exception e) {
// e.printStackTrace();
}
return response;
}
Aggregations