-
Notifications
You must be signed in to change notification settings - Fork 117
Description
I see WinRMAuthorizationError, but unless GitHub's code search is failing me it appears to be unused.
Also, a lot of rather different errors are grouped into WinRMHTTPTransportError. In Vagrant, the handling of the error currently looks like this:
if winrm_exception.message.include?("401")
raise Errors::AuthError,
user: @config.username,
password: @config.password,
endpoint: endpoint,
message: winrm_exception.message
endI think it'd be good if we could access the error code directly, because it's easy to group HTTP response codes into different types of errors. All of 4xx is "client errors" while 5xx is "server errors", so we can at least tell users if something went wrong on their end or if the server. I can also group errors into retriable (like 504 Gateway Timeout), recoverable (with extra code, like 440 Login Timeout (Microsoft) or 449 Retry With (Microsoft)) and definitely not recoverable (403 Forbidden or 405 Method Not Allowed).
So I'd like if WinRMHTTPTransportError saved the status_code as an attribute so I could do:
rescue WinRMHTTPTransportError => e
case e.status_code
when 502..504
# retry
when 440, 449
# reauthenticate then retry
when 400..499
# display friendly client error message
when 500..599
# display friendly server error message
else
# A 1xx, 2xx or 3xx error? Explode!
end