-
Notifications
You must be signed in to change notification settings - Fork 1.7k
#2375 #2376 Map non-ASCII header HttpRequestException to 400 Bad Request
#2379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 1 commit
001efdf
7dd44b4
d3d26f6
6f7fd84
16b9211
51efe4e
ee31a53
2411b59
803d06b
d1246cb
6c93d12
cf13333
e2b0001
2e23dd9
43f6aee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| using System; | ||
| using Ocelot.Errors; | ||
|
|
||
| namespace Ocelot.Requester; | ||
|
|
||
| public class BadRequestError : Error | ||
| { | ||
| public BadRequestError(string message) | ||
| : base(message, OcelotErrorCode.BadRequestError, 400) | ||
|
raman-m marked this conversation as resolved.
Outdated
|
||
| { | ||
| } | ||
| } | ||
|
raman-m marked this conversation as resolved.
Outdated
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,6 +47,14 @@ public Error Map(Exception exception) | |
| return new PayloadTooLargeError(exception); | ||
| } | ||
|
|
||
| // Late Catch: Map the HttpRequestException to a 400 Bad Request. | ||
| // If the header format is invalid, HttpClient throws this exception locally. | ||
| // By catching it here, we ensure Ocelot returns a clean 4xx client error instead of a generic 502 Bad Gateway. | ||
| if (exception is HttpRequestException && exception.Message.Contains("only ASCII characters")) | ||
|
raman-m marked this conversation as resolved.
Outdated
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It’s hard to judge this solution until a valid acceptance test has been written. I believe we can improve this area, since the We might also consider covering more scenarios that return a
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Appreciate the guidance |
||
| { | ||
| return new BadRequestError(exception.Message); | ||
| } | ||
|
|
||
| return new ConnectionToDownstreamServiceError(exception); | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.