1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.bremersee.exception.feign;
18
19 import feign.FeignException;
20 import feign.Request;
21 import java.util.Collection;
22 import java.util.Map;
23 import lombok.Getter;
24 import org.bremersee.exception.HttpStatusAware;
25 import org.bremersee.exception.RestApiExceptionAware;
26 import org.bremersee.exception.model.RestApiException;
27 import org.springframework.http.HttpStatus;
28
29
30
31
32
33
34
35
36 @Getter
37 public class FeignClientException extends FeignException
38 implements HttpStatusAware, RestApiExceptionAware {
39
40
41
42
43 private final RestApiException restApiException;
44
45
46
47
48
49
50
51
52
53
54
55 public FeignClientException(
56 int status,
57 String message,
58 Request request,
59 Map<String, Collection<String>> responseHeaders,
60 byte[] responseBody,
61 RestApiException restApiException) {
62
63 super(
64 resolveHttpStatusCode(status),
65 message,
66 request,
67 responseBody,
68 responseHeaders);
69 this.restApiException = restApiException;
70 }
71
72 private static int resolveHttpStatusCode(int httpStatusCode) {
73 HttpStatus httpStatus = HttpStatus.resolve(httpStatusCode);
74 return httpStatus != null ? httpStatus.value() : HttpStatus.INTERNAL_SERVER_ERROR.value();
75 }
76
77 }