Understanding HttpResponseException in UiPath

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 CodeDescription
400–417Client errors (e.g. BadRequest, Unauthorized, etc.)
421–431More client errors
451Legal restriction error
500–511Server errors (e.g. InternalServerError, GatewayTimeout, etc.)
408May trigger TaskCanceledException if timeout occurs
429Often 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 CodeDescription
100–103Informational responses
200–226Successful responses
300–308Redirection responses

🧠 Exception Behavior in .NET

  • HttpClient does not throw exceptions for non-success status codes unless you call response.EnsureSuccessStatusCode().

  • Timeouts or network failures may throw TaskCanceledException, HttpRequestException, or OperationCanceledException.

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 CodeHttpResponseException

Description
400System.Net.HttpStatusCode.BadRequestEquivalent 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.
401System.Net.HttpStatusCode.UnauthorizedEquivalent 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.
402System.Net.HttpStatusCode.PaymentRequiredEquivalent to HTTP status 402. PaymentRequired is reserved for future use.
403System.Net.HttpStatusCode.ForbiddenEquivalent to HTTP status 403. Forbidden indicates that the server refuses to fulfill the request.
404System.Net.HttpStatusCode.NotFoundEquivalent to HTTP status 404. NotFound indicates that the requested resource does not exist on the server.
405System.Net.HttpStatusCode.MethodNotAllowedEquivalent to HTTP status 405. MethodNotAllowed indicates that the request method (POST or GET) is not allowed on the requested resource.
406System.Net.HttpStatusCode.NotAcceptableEquivalent 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.
407System.Net.HttpStatusCode.ProxyAuthenticationRequiredEquivalent 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.
408System.Net.HttpStatusCode.RequestTimeoutEquivalent to HTTP status 408. RequestTimeout indicates that the client did not send a request within the time the server was expecting the request.
409System.Net.HttpStatusCode.ConflictEquivalent to HTTP status 409. Conflict indicates that the request could not be carried out because of a conflict on the server.
410System.Net.HttpStatusCode.GoneEquivalent to HTTP status 410. Gone indicates that the requested resource is no longer available.
411System.Net.HttpStatusCode.LengthRequiredEquivalent to HTTP status 411. LengthRequired indicates that the required Content-length header is missing.
412System.Net.HttpStatusCode.PreconditionFailedEquivalent 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.
413System.Net.HttpStatusCode.RequestEntityTooLargeEquivalent to HTTP status 413. RequestEntityTooLarge indicates that the request is too large for the server to process.
414System.Net.HttpStatusCode.RequestUriTooLongEquivalent to HTTP status 414. RequestUriTooLong indicates that the URI is too long.
415System.Net.HttpStatusCode.UnsupportedMediaTypeEquivalent to HTTP status 415. UnsupportedMediaType indicates that the request is an unsupported type.
416System.Net.HttpStatusCode.RequestedRangeNotSatisfiableEquivalent 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.
417System.Net.HttpStatusCode.ExpectationFailedEquivalent to HTTP status 417. ExpectationFailed indicates that an expectation given in an Expect header could not be met by the server.
421System.Net.HttpStatusCode.MisdirectedRequestEquivalent to HTTP status 421. MisdirectedRequest indicates that the request was directed at a server that is not able to produce a response.
422System.Net.HttpStatusCode.UnprocessableContentEquivalent 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.
422System.Net.HttpStatusCode.UnprocessableEntityEquivalent 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.
423System.Net.HttpStatusCode.LockedEquivalent to HTTP status 423. Locked indicates that the source or destination resource is locked.
424System.Net.HttpStatusCode.FailedDependencyEquivalent 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.
426System.Net.HttpStatusCode.UpgradeRequiredEquivalent to HTTP status 426. UpgradeRequired indicates that the client should switch to a different protocol such as TLS/1.0.
428System.Net.HttpStatusCode.PreconditionRequiredEquivalent to HTTP status 428. PreconditionRequired indicates that the server requires the request to be conditional.
429System.Net.HttpStatusCode.TooManyRequestsEquivalent to HTTP status 429. TooManyRequests indicates that the user has sent too many requests in a given amount of time.
431System.Net.HttpStatusCode.RequestHeaderFieldsTooLargeEquivalent 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.
451System.Net.HttpStatusCode.UnavailableForLegalReasonsEquivalent to HTTP status 451. UnavailableForLegalReasons indicates that the server is denying access to the resource as a consequence of a legal demand.
500System.Net.HttpStatusCode.InternalServerErrorEquivalent to HTTP status 500. InternalServerError indicates that a generic error has occurred on the server.
501System.Net.HttpStatusCode.NotImplementedEquivalent to HTTP status 501. NotImplemented indicates that the server does not support the requested function.
502System.Net.HttpStatusCode.BadGatewayEquivalent to HTTP status 502. BadGateway indicates that an intermediate proxy server received a bad response from another proxy or the origin server.
503System.Net.HttpStatusCode.ServiceUnavailableEquivalent to HTTP status 503. ServiceUnavailable indicates that the server is temporarily unavailable, usually due to high load or maintenance.
504System.Net.HttpStatusCode.GatewayTimeoutEquivalent 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.
505System.Net.HttpStatusCode.HttpVersionNotSupportedEquivalent to HTTP status 505. HttpVersionNotSupported indicates that the requested HTTP version is not supported by the server.
506System.Net.HttpStatusCode.VariantAlsoNegotiatesEquivalent 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.
507System.Net.HttpStatusCode.InsufficientStorageEquivalent to HTTP status 507. InsufficientStorage indicates that the server is unable to store the representation needed to complete the request.
508System.Net.HttpStatusCode.LoopDetectedEquivalent 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.
510System.Net.HttpStatusCode.NotExtendedEquivalent to HTTP status 510. NotExtended indicates that further extensions to the request are required for the server to fulfill it.
511System.Net.HttpStatusCode.NetworkAuthenticationRequiredEquivalent 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.