@@ -75,7 +75,46 @@ public static FeignException errorStatus(String methodKey, Response response) {
7575 } catch (IOException ignored ) { // NOPMD
7676 }
7777
78- return new FeignException (response .status (), message , body );
78+ return errorStatus (response .status (), message , body );
79+ }
80+
81+ private static FeignException errorStatus (int status , String message , byte [] body ) {
82+ switch (status ) {
83+ case 400 :
84+ return new BadRequest (message , body );
85+ case 401 :
86+ return new Unauthorized (message , body );
87+ case 403 :
88+ return new Forbidden (message , body );
89+ case 404 :
90+ return new NotFound (message , body );
91+ case 405 :
92+ return new MethodNotAllowed (message , body );
93+ case 406 :
94+ return new NotAcceptable (message , body );
95+ case 409 :
96+ return new Conflict (message , body );
97+ case 410 :
98+ return new Gone (message , body );
99+ case 415 :
100+ return new UnsupportedMediaType (message , body );
101+ case 429 :
102+ return new TooManyRequests (message , body );
103+ case 422 :
104+ return new UnprocessableEntity (message , body );
105+ case 500 :
106+ return new InternalServerError (message , body );
107+ case 501 :
108+ return new NotImplemented (message , body );
109+ case 502 :
110+ return new BadGateway (message , body );
111+ case 503 :
112+ return new ServiceUnavailable (message , body );
113+ case 504 :
114+ return new GatewayTimeout (message , body );
115+ default :
116+ return new FeignException (status , message , body );
117+ }
79118 }
80119
81120 static FeignException errorExecuting (Request request , IOException cause ) {
@@ -85,4 +124,100 @@ static FeignException errorExecuting(Request request, IOException cause) {
85124 cause ,
86125 null );
87126 }
127+
128+ public static class BadRequest extends FeignException {
129+ public BadRequest (String message , byte [] body ) {
130+ super (400 , message , body );
131+ }
132+ }
133+
134+ public static class Unauthorized extends FeignException {
135+ public Unauthorized (String message , byte [] body ) {
136+ super (401 , message , body );
137+ }
138+ }
139+
140+ public static class Forbidden extends FeignException {
141+ public Forbidden (String message , byte [] body ) {
142+ super (403 , message , body );
143+ }
144+ }
145+
146+ public static class NotFound extends FeignException {
147+ public NotFound (String message , byte [] body ) {
148+ super (404 , message , body );
149+ }
150+ }
151+
152+ public static class MethodNotAllowed extends FeignException {
153+ public MethodNotAllowed (String message , byte [] body ) {
154+ super (405 , message , body );
155+ }
156+ }
157+
158+ public static class NotAcceptable extends FeignException {
159+ public NotAcceptable (String message , byte [] body ) {
160+ super (406 , message , body );
161+ }
162+ }
163+
164+ public static class Conflict extends FeignException {
165+ public Conflict (String message , byte [] body ) {
166+ super (409 , message , body );
167+ }
168+ }
169+
170+ public static class Gone extends FeignException {
171+ public Gone (String message , byte [] body ) {
172+ super (410 , message , body );
173+ }
174+ }
175+
176+ public static class UnsupportedMediaType extends FeignException {
177+ public UnsupportedMediaType (String message , byte [] body ) {
178+ super (415 , message , body );
179+ }
180+ }
181+
182+ public static class TooManyRequests extends FeignException {
183+ public TooManyRequests (String message , byte [] body ) {
184+ super (429 , message , body );
185+ }
186+ }
187+
188+ public static class UnprocessableEntity extends FeignException {
189+ public UnprocessableEntity (String message , byte [] body ) {
190+ super (422 , message , body );
191+ }
192+ }
193+
194+ public static class InternalServerError extends FeignException {
195+ public InternalServerError (String message , byte [] body ) {
196+ super (500 , message , body );
197+ }
198+ }
199+
200+ public static class NotImplemented extends FeignException {
201+ public NotImplemented (String message , byte [] body ) {
202+ super (501 , message , body );
203+ }
204+ }
205+
206+ public static class BadGateway extends FeignException {
207+ public BadGateway (String message , byte [] body ) {
208+ super (502 , message , body );
209+ }
210+ }
211+
212+ public static class ServiceUnavailable extends FeignException {
213+ public ServiceUnavailable (String message , byte [] body ) {
214+ super (503 , message , body );
215+ }
216+ }
217+
218+ public static class GatewayTimeout extends FeignException {
219+ public GatewayTimeout (String message , byte [] body ) {
220+ super (504 , message , body );
221+ }
222+ }
88223}
0 commit comments