com.loocme.sys.exception.HttpConnectionException Maven / Gradle / Ivy
package com.loocme.sys.exception;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;
/**
* http请求时异常信息
*
* @author loocme
*
*/
public class HttpConnectionException extends Exception
{
private static final long serialVersionUID = 1L;
private static final int HTTP_CODE_SUCC_MIN = 200;
private static final Map ERROR_MSG = new HashMap<>();
static
{
ERROR_MSG.put(400, "请求参数无效");
ERROR_MSG.put(404, "请求url资源未找到");
ERROR_MSG.put(503, "程序异常,请检查");
}
private int status;
private String msg;
public HttpConnectionException(int status)
{
super();
this.status = status;
}
public HttpConnectionException(int status, String msg)
{
super();
this.status = status;
this.msg = msg;
}
public HttpConnectionException(int status, Exception e)
{
super();
this.status = status;
this.msg = e.getMessage();
}
public HttpConnectionException(Throwable cause)
{
super(cause);
this.status = -1;
}
/**
* @return the status
*/
public int getStatus()
{
return status;
}
/**
* @see java.lang.Throwable#getMessage()
*/
@Override
public String getMessage()
{
if (-1 == this.status)
{
return super.getMessage();
}
if (this.status < HTTP_CODE_SUCC_MIN)
{
return this.msg;
}
String msgStr = "";
if (ERROR_MSG.containsKey(this.status))
{
msgStr = ERROR_MSG.get(this.status);
}
else
{
msgStr = this.status + ":" + this.msg;
}
return msgStr;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy