@@ -126,8 +126,191 @@ public static HttpException Create(object content, IList<HttpHeader> headers, st
126126 if ( string . IsNullOrEmpty ( errorMessage ) ) errorMessage = ErrorMessage ;
127127 if ( string . IsNullOrEmpty ( errorMessage ) ) errorMessage = stringBody ;
128128
129- return new HttpException ( errorMessage , ( int ) statusCode , exception )
130- { ErrorBody = errorBody , RetryAfter = retryAfter } ;
129+ var err = ( int ) statusCode switch
130+ {
131+ 400 => new BadRequestException ( errorMessage , exception ) ,
132+ 401 => new UnauthorizedException ( errorMessage , exception ) ,
133+ 402 => new PaymentRequiredException ( errorMessage , exception ) ,
134+ 403 => new ForbiddenException ( errorMessage , exception ) ,
135+ 404 => new NotFoundException ( errorMessage , exception ) ,
136+ 405 => new MethodNotAllowedException ( errorMessage , exception ) ,
137+ 406 => new NotAcceptableException ( errorMessage , exception ) ,
138+ 407 => new ProxyAuthenticationRequiredException ( errorMessage , exception ) ,
139+ 408 => new RequestTimeoutException ( errorMessage , exception ) ,
140+ 413 => new RequestEntityTooLargeException ( errorMessage , exception ) ,
141+ 422 => new UnprocessableEntityException ( errorMessage , exception ) ,
142+ 429 => new TooManyRequestsException ( errorMessage , exception ) ,
143+ 500 => new InternalServerErrorException ( errorMessage , exception ) ,
144+ 501 => new HttpNotImplementedException ( errorMessage , exception ) ,
145+ 502 => new BadGatewayException ( errorMessage , exception ) ,
146+ 503 => new ServiceUnavailableException ( errorMessage , exception ) ,
147+ _ => new HttpException ( errorMessage , ( int ) statusCode , exception )
148+ } ;
149+
150+ err . ErrorBody = errorBody ;
151+ err . RetryAfter = retryAfter ;
152+
153+ return err ;
154+ }
155+ }
156+
157+ /// <summary>
158+ /// The exception for response: HTTP 400 - Bad Request.
159+ /// </summary>
160+ public class BadRequestException : HttpException
161+ {
162+ public BadRequestException ( string message , Exception exception = null ) : base ( message , 400 , exception )
163+ {
164+ }
165+ }
166+
167+ /// <summary>
168+ /// The exception for response: HTTP 401 - Unauthorized.
169+ /// </summary>
170+ public class UnauthorizedException : HttpException
171+ {
172+ public UnauthorizedException ( string message , Exception exception = null ) : base ( message , 401 , exception )
173+ {
174+ }
175+ }
176+
177+ /// <summary>
178+ /// The exception for response: HTTP 402 - Payment Required.
179+ /// </summary>
180+ public class PaymentRequiredException : HttpException
181+ {
182+ public PaymentRequiredException ( string message , Exception exception = null ) : base ( message , 402 , exception )
183+ {
184+ }
185+ }
186+
187+ /// <summary>
188+ /// The exception for response: HTTP 403 - Forbidden.
189+ /// </summary>
190+ public class ForbiddenException : HttpException
191+ {
192+ public ForbiddenException ( string message , Exception exception = null ) : base ( message , 403 , exception )
193+ {
194+ }
195+ }
196+
197+ /// <summary>
198+ /// The exception for response: HTTP 404 - Not Found.
199+ /// </summary>
200+ public class NotFoundException : HttpException
201+ {
202+ public NotFoundException ( string message , Exception exception = null ) : base ( message , 404 , exception )
203+ {
204+ }
205+ }
206+
207+ /// <summary>
208+ /// The exception for response: HTTP 405 - Method Not Allowed.
209+ /// </summary>
210+ public class MethodNotAllowedException : HttpException
211+ {
212+ public MethodNotAllowedException ( string message , Exception exception = null ) : base ( message , 405 , exception )
213+ {
214+ }
215+ }
216+
217+ /// <summary>
218+ /// The exception for response: HTTP 406 - Not Acceptable.
219+ /// </summary>
220+ public class NotAcceptableException : HttpException
221+ {
222+ public NotAcceptableException ( string message , Exception exception = null ) : base ( message , 406 , exception )
223+ {
224+ }
225+ }
226+
227+ /// <summary>
228+ /// The exception for response: HTTP 407 - Proxy Authentication Required.
229+ /// </summary>
230+ public class ProxyAuthenticationRequiredException : HttpException
231+ {
232+ public ProxyAuthenticationRequiredException ( string message , Exception exception = null ) : base ( message , 407 , exception )
233+ {
234+ }
235+ }
236+
237+ /// <summary>
238+ /// The exception for response: HTTP 408 - Request Timeout.
239+ /// </summary>
240+ public class RequestTimeoutException : HttpException
241+ {
242+ public RequestTimeoutException ( string message , Exception exception = null ) : base ( message , 408 , exception )
243+ {
244+ }
245+ }
246+
247+ /// <summary>
248+ /// The exception for response: HTTP 413 - Request Entity Too Large.
249+ /// </summary>
250+ public class RequestEntityTooLargeException : HttpException
251+ {
252+ public RequestEntityTooLargeException ( string message , Exception exception = null ) : base ( message , 413 , exception )
253+ {
254+ }
255+ }
256+
257+ /// <summary>
258+ /// The exception for response: HTTP 422 - Unprocessable Entity.
259+ /// </summary>
260+ public class UnprocessableEntityException : HttpException
261+ {
262+ public UnprocessableEntityException ( string message , Exception exception = null ) : base ( message , 422 , exception )
263+ {
264+ }
265+ }
266+
267+ /// <summary>
268+ /// The exception for response: HTTP 429 - Too Many Requests.
269+ /// </summary>
270+ public class TooManyRequestsException : HttpException
271+ {
272+ public TooManyRequestsException ( string message , Exception exception = null ) : base ( message , 429 , exception )
273+ {
274+ }
275+ }
276+
277+ /// <summary>
278+ /// The exception for response: HTTP 500 - Internal Server Error.
279+ /// </summary>
280+ public class InternalServerErrorException : HttpException
281+ {
282+ public InternalServerErrorException ( string message , Exception exception = null ) : base ( message , 500 , exception )
283+ {
284+ }
285+ }
286+
287+ /// <summary>
288+ /// The exception for response: HTTP 501 - Not Implemented.
289+ /// </summary>
290+ public class HttpNotImplementedException : HttpException
291+ {
292+ public HttpNotImplementedException ( string message , Exception exception = null ) : base ( message , 501 , exception )
293+ {
294+ }
295+ }
296+
297+ /// <summary>
298+ /// The exception for response: HTTP 502 - Bad Gateway.
299+ /// </summary>
300+ public class BadGatewayException : HttpException
301+ {
302+ public BadGatewayException ( string message , Exception exception = null ) : base ( message , 502 , exception )
303+ {
304+ }
305+ }
306+
307+ /// <summary>
308+ /// The exception for response: HTTP 503 - Service Unavailable.
309+ /// </summary>
310+ public class ServiceUnavailableException : HttpException
311+ {
312+ public ServiceUnavailableException ( string message , Exception exception = null ) : base ( message , 503 , exception )
313+ {
131314 }
132315 }
133316}
0 commit comments