CallRet.java 1.84 KB
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
package com.lyms.cm.qiniu;

/**
* The CallRet class represents a general response from qiniu server.
*
*/
public class CallRet {
/** http status code */
public int statusCode;

/** The http response body */
public String response;

/** Any exception when dealing with the request */
public Exception exception;

public CallRet() {
}

/**
* Constructs a new CallRet with the specified statusCode and response.
*
* @param statusCode
* http status code
* @param response
* http reponse body
*/
public CallRet(int statusCode, String response) {
this.statusCode = statusCode;
this.response = response;
}

/**
* Construct a new CallRet with the the specifed statusCode and exception.
*
* @param statusCode
* the http status code
* @param e
* any exception resulting from dealing the use's request.
*/
public CallRet(int statusCode, Exception e) {
this.statusCode = statusCode;
this.exception = e;
}

/**
* Construct a new CallRet with the specified ret, behaves like copy
* constructor.
*
* @param ret
*/
public CallRet(CallRet ret) {
this.statusCode = ret.statusCode;
this.exception = ret.exception;
this.response = ret.response;
}

public int getStatusCode() {
return this.statusCode;
}

public String getResponse() {
return this.response;
}

/**
*
*
* @return {@code true} if successfully processed the user's request, return
* true. {@code false} otherwise
*/
public boolean ok() {
return this.statusCode / 100 == 2 && this.exception == null;
}

public Exception getException() {
return this.exception;
}

@Override
public String toString() {
if (this.exception != null) {
return this.exception.getMessage();
}
if (this.response != null) {
return this.response;
}

return String.valueOf(this.statusCode);
}
}