com.cmonbaby.http.exception.HttpException Maven / Gradle / Ivy
Show all versions of http_lower Show documentation
package com.cmonbaby.http.exception;
import retrofit2.Response;
/**
* Author: Simon
*
QO: 8950764
*
Email: [email protected]
*
WebSize: https://www.cmonbaby.com
*
Version: 1.0.0
*
Date: 2020/12/28
*
Description: Exception for an unexpected, non-2xx HTTP response.
*/
public final class HttpException extends Exception {
private static String getMessage(Response> response) {
if (response == null) throw new NullPointerException("response == null");
return "HTTP " + response.code() + " " + response.message();
}
private final int code;
private final String message;
private final transient Response> response;
public HttpException(Response> response) {
super(getMessage(response));
this.code = response.code();
this.message = response.message();
this.response = response;
}
/**
* HTTP status code.
*/
public int code() {
return code;
}
/**
* HTTP status message.
*/
public String message() {
return message;
}
/**
* The full HTTP response. This may be null if the exception was serialized.
*/
public Response> response() {
return response;
}
}