Understanding HttpResponseException Exceptions in UiPath
📘 Understanding HttpResponseException in UiPath: Why This HTTP Status Code Table Matters
When working with UiPath robots that interact with web services or APIs, it's common to encounter .NET exceptions - especially those related to HTTP requests. These exceptions often appear in logs or during runtime, and without proper context, they can be cryptic and hard to diagnose.
🚫 Status Codes That Commonly Trigger Exceptions
These are usually client errors (4xx) or server errors (5xx). They don’t always throw exceptions automatically, but they indicate failure and may cause HttpRequestException or other exceptions depending on how your code handles responses.
| Status Code | Description |
|---|---|
| 400–417 | Client errors (e.g. BadRequest, Unauthorized, etc.) |
| 421–431 | More client errors |
| 451 | Legal restriction error |
| 500–511 | Server errors (e.g. InternalServerError, GatewayTimeout, etc.) |
| 408 | May trigger TaskCanceledException if timeout occurs |
| 429 | Often used for rate limiting—can be handled explicitly |
✅ Status Codes That Do Not Trigger Exceptions
These are informational (1xx), successful (2xx), and redirection (3xx) codes. They do not throw exceptions by default unless your code explicitly treats them as failures.
| Status Code | Description |
|---|---|
| 100–103 | Informational responses |
| 200–226 | Successful responses |
| 300–308 | Redirection responses |
🧠 Exception Behavior in .NET
-
HttpClientdoes not throw exceptions for non-success status codes unless you callresponse.EnsureSuccessStatusCode(). -
Timeouts or network failures may throw
TaskCanceledException,HttpRequestException, orOperationCanceledException.
This is where a reference table mapping HTTP status codes to their corresponding .NET exceptions and descriptions becomes invaluable.
🔍 Why This Table Is Useful
- Faster Troubleshooting: When a robot fails due to a System.Net.HttpStatusCode exception, this table helps quickly identify the root cause—whether it's a timeout, unauthorized access, or server error.
- Improved Logging Interpretation: Developers and support teams can correlate log entries with known HTTP behaviors, making it easier to pinpoint issues.
- Better Exception Handling: By understanding which status codes are likely to trigger exceptions, developers can implement more robust retry logic, fallback mechanisms, or user-friendly error messages.
- Standardized Documentation: Having a consistent reference improves team communication and onboarding for new developers working with UiPath and APIs.
🧠 Example Use Case
Imagine a robot fails with a System.Net.HttpStatusCode.ServiceUnavailable exception. Instead of guessing, you refer to the table and see that this corresponds to a 503 status code—indicating the server is temporarily overloaded or down. You now know to implement a retry with exponential backoff or notify the user to try again later.
| Status Code | HttpResponseException | Description |
|---|---|---|
| 400 | System.Net.HttpStatusCode.BadRequest | Equivalent to HTTP status 400. BadRequest indicates that the request could not be understood by the server. BadRequest is sent when no other error is applicable, or if the exact error is unknown or does not have its own error code. |
| 401 | System.Net.HttpStatusCode.Unauthorized | Equivalent to HTTP status 401. Unauthorized indicates that the requested resource requires authentication. The WWW-Authenticate header contains the details of how to perform the authentication. |
| 402 | System.Net.HttpStatusCode.PaymentRequired | Equivalent to HTTP status 402. PaymentRequired is reserved for future use. |
| 403 | System.Net.HttpStatusCode.Forbidden | Equivalent to HTTP status 403. Forbidden indicates that the server refuses to fulfill the request. |
| 404 | System.Net.HttpStatusCode.NotFound | Equivalent to HTTP status 404. NotFound indicates that the requested resource does not exist on the server. |
| 405 | System.Net.HttpStatusCode.MethodNotAllowed | Equivalent to HTTP status 405. MethodNotAllowed indicates that the request method (POST or GET) is not allowed on the requested resource. |
| 406 | System.Net.HttpStatusCode.NotAcceptable | Equivalent to HTTP status 406. NotAcceptable indicates that the client has indicated with Accept headers that it will not accept any of the available representations of the resource. |
| 407 | System.Net.HttpStatusCode.ProxyAuthenticationRequired | Equivalent to HTTP status 407. ProxyAuthenticationRequired indicates that the requested proxy requires authentication. The Proxy-authenticate header contains the details of how to perform the authentication. |
| 408 | System.Net.HttpStatusCode.RequestTimeout | Equivalent to HTTP status 408. RequestTimeout indicates that the client did not send a request within the time the server was expecting the request. |
| 409 | System.Net.HttpStatusCode.Conflict | Equivalent to HTTP status 409. Conflict indicates that the request could not be carried out because of a conflict on the server. |
| 410 | System.Net.HttpStatusCode.Gone | Equivalent to HTTP status 410. Gone indicates that the requested resource is no longer available. |
| 411 | System.Net.HttpStatusCode.LengthRequired | Equivalent to HTTP status 411. LengthRequired indicates that the required Content-length header is missing. |
| 412 | System.Net.HttpStatusCode.PreconditionFailed | Equivalent to HTTP status 412. PreconditionFailed indicates that a condition set for this request failed, and the request cannot be carried out. Conditions are set with conditional request headers like If-Match, If-None-Match, or If-Unmodified-Since. |
| 413 | System.Net.HttpStatusCode.RequestEntityTooLarge | Equivalent to HTTP status 413. RequestEntityTooLarge indicates that the request is too large for the server to process. |
| 414 | System.Net.HttpStatusCode.RequestUriTooLong | Equivalent to HTTP status 414. RequestUriTooLong indicates that the URI is too long. |
| 415 | System.Net.HttpStatusCode.UnsupportedMediaType | Equivalent to HTTP status 415. UnsupportedMediaType indicates that the request is an unsupported type. |
| 416 | System.Net.HttpStatusCode.RequestedRangeNotSatisfiable | Equivalent to HTTP status 416. RequestedRangeNotSatisfiable indicates that the range of data requested from the resource cannot be returned, either because the beginning of the range is before the beginning of the resource, or the end of the range is after the end of the resource. |
| 417 | System.Net.HttpStatusCode.ExpectationFailed | Equivalent to HTTP status 417. ExpectationFailed indicates that an expectation given in an Expect header could not be met by the server. |
| 421 | System.Net.HttpStatusCode.MisdirectedRequest | Equivalent to HTTP status 421. MisdirectedRequest indicates that the request was directed at a server that is not able to produce a response. |
| 422 | System.Net.HttpStatusCode.UnprocessableContent | Equivalent to HTTP status 422. UnprocessableContent indicates that the request was well-formed but was unable to be followed due to semantic errors. UnprocessableContent is a synonym for UnprocessableEntity. |
| 422 | System.Net.HttpStatusCode.UnprocessableEntity | Equivalent to HTTP status 422. UnprocessableEntity indicates that the request was well-formed but was unable to be followed due to semantic errors. UnprocessableEntity is a synonym for UnprocessableContent. |
| 423 | System.Net.HttpStatusCode.Locked | Equivalent to HTTP status 423. Locked indicates that the source or destination resource is locked. |
| 424 | System.Net.HttpStatusCode.FailedDependency | Equivalent to HTTP status 424. FailedDependency indicates that the method couldn't be performed on the resource because the requested action depended on another action and that action failed. |
| 426 | System.Net.HttpStatusCode.UpgradeRequired | Equivalent to HTTP status 426. UpgradeRequired indicates that the client should switch to a different protocol such as TLS/1.0. |
| 428 | System.Net.HttpStatusCode.PreconditionRequired | Equivalent to HTTP status 428. PreconditionRequired indicates that the server requires the request to be conditional. |
| 429 | System.Net.HttpStatusCode.TooManyRequests | Equivalent to HTTP status 429. TooManyRequests indicates that the user has sent too many requests in a given amount of time. |
| 431 | System.Net.HttpStatusCode.RequestHeaderFieldsTooLarge | Equivalent to HTTP status 431. RequestHeaderFieldsTooLarge indicates that the server is unwilling to process the request because its header fields (either an individual header field or all the header fields collectively) are too large. |
| 451 | System.Net.HttpStatusCode.UnavailableForLegalReasons | Equivalent to HTTP status 451. UnavailableForLegalReasons indicates that the server is denying access to the resource as a consequence of a legal demand. |
| 500 | System.Net.HttpStatusCode.InternalServerError | Equivalent to HTTP status 500. InternalServerError indicates that a generic error has occurred on the server. |
| 501 | System.Net.HttpStatusCode.NotImplemented | Equivalent to HTTP status 501. NotImplemented indicates that the server does not support the requested function. |
| 502 | System.Net.HttpStatusCode.BadGateway | Equivalent to HTTP status 502. BadGateway indicates that an intermediate proxy server received a bad response from another proxy or the origin server. |
| 503 | System.Net.HttpStatusCode.ServiceUnavailable | Equivalent to HTTP status 503. ServiceUnavailable indicates that the server is temporarily unavailable, usually due to high load or maintenance. |
| 504 | System.Net.HttpStatusCode.GatewayTimeout | Equivalent to HTTP status 504. GatewayTimeout indicates that an intermediate proxy server timed out while waiting for a response from another proxy or the origin server. |
| 505 | System.Net.HttpStatusCode.HttpVersionNotSupported | Equivalent to HTTP status 505. HttpVersionNotSupported indicates that the requested HTTP version is not supported by the server. |
| 506 | System.Net.HttpStatusCode.VariantAlsoNegotiates | Equivalent to HTTP status 506. VariantAlsoNegotiates indicates that the chosen variant resource is configured to engage in transparent content negotiation itself and, therefore, isn't a proper endpoint in the negotiation process. |
| 507 | System.Net.HttpStatusCode.InsufficientStorage | Equivalent to HTTP status 507. InsufficientStorage indicates that the server is unable to store the representation needed to complete the request. |
| 508 | System.Net.HttpStatusCode.LoopDetected | Equivalent to HTTP status 508. LoopDetected indicates that the server terminated an operation because it encountered an infinite loop while processing a WebDAV request with "Depth: infinity". This status code is meant for backward compatibility with clients not aware of the 208 status code AlreadyReported appearing in multistatus response bodies. |
| 510 | System.Net.HttpStatusCode.NotExtended | Equivalent to HTTP status 510. NotExtended indicates that further extensions to the request are required for the server to fulfill it. |
| 511 | System.Net.HttpStatusCode.NetworkAuthenticationRequired | Equivalent to HTTP status 511. NetworkAuthenticationRequired indicates that the client needs to authenticate to gain network access; it's intended for use by intercepting proxies used to control access to the network. |
📎 Reference
For a complete list of HTTP status codes and their definitions in .NET, see the official documentation on System.Net.HttpStatusCode.