| 1 | |
package com.ctrip.apollo.common.http; |
| 2 | |
|
| 3 | |
import org.springframework.http.HttpStatus; |
| 4 | |
|
| 5 | 0 | public class RichResponseEntity<T>{ |
| 6 | |
|
| 7 | |
private int code; |
| 8 | |
private Object message; |
| 9 | |
private T body; |
| 10 | |
|
| 11 | |
public static <T> RichResponseEntity<T> ok(T body){ |
| 12 | 0 | RichResponseEntity<T> richResponseEntity = new RichResponseEntity<>(); |
| 13 | 0 | richResponseEntity.message = HttpStatus.OK.getReasonPhrase(); |
| 14 | 0 | richResponseEntity.code = HttpStatus.OK.value(); |
| 15 | 0 | richResponseEntity.body = body; |
| 16 | 0 | return richResponseEntity; |
| 17 | |
} |
| 18 | |
|
| 19 | |
public static <T> RichResponseEntity<T> error(HttpStatus httpCode, Object message){ |
| 20 | 0 | RichResponseEntity<T> richResponseEntity = new RichResponseEntity<>(); |
| 21 | 0 | richResponseEntity.message = message; |
| 22 | 0 | richResponseEntity.code = httpCode.value(); |
| 23 | 0 | return richResponseEntity; |
| 24 | |
} |
| 25 | |
|
| 26 | |
public int getCode() { |
| 27 | 0 | return code; |
| 28 | |
} |
| 29 | |
|
| 30 | |
public Object getMessage() { |
| 31 | 0 | return message; |
| 32 | |
} |
| 33 | |
|
| 34 | |
public T getBody() { |
| 35 | 0 | return body; |
| 36 | |
} |
| 37 | |
} |