Skip to content

Commit b77d9e0

Browse files
authored
feat: add error code unauthorized (#313)
* feat: add error code unauthorized This makes it possible to check for an invalid token using `hcloud.IsError(err, hcloud.ErrorCodeUnauthorized)`. * docs: cleanup error codes comments The "header" comment previously showed up for the first error code of that category. By adding an empty line inbetween the two are no longer connected. By using "Deprecated: " tooling will automatically show a deprecation warning for the `ErrorCodeLimitReached` constant.
1 parent 60f452f commit b77d9e0

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

hcloud/error.go

+14-6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const (
1616
ErrorCodeNotFound ErrorCode = "not_found" // Resource not found
1717
ErrorCodeInvalidInput ErrorCode = "invalid_input" // Validation error
1818
ErrorCodeForbidden ErrorCode = "forbidden" // Insufficient permissions
19+
ErrorCodeUnauthorized ErrorCode = "unauthorized" // Request was made with an invalid or unknown token
1920
ErrorCodeJSONError ErrorCode = "json_error" // Invalid JSON in request
2021
ErrorCodeLocked ErrorCode = "locked" // Item is locked (Another action is running)
2122
ErrorCodeResourceLimitExceeded ErrorCode = "resource_limit_exceeded" // Resource limit exceeded
@@ -29,13 +30,15 @@ const (
2930
ErrorUnsupportedError ErrorCode = "unsupported_error" // The given resource does not support this
3031

3132
// Server related error codes.
33+
3234
ErrorCodeInvalidServerType ErrorCode = "invalid_server_type" // The server type does not fit for the given server or is deprecated
3335
ErrorCodeServerNotStopped ErrorCode = "server_not_stopped" // The action requires a stopped server
3436
ErrorCodeNetworksOverlap ErrorCode = "networks_overlap" // The network IP range overlaps with one of the server networks
3537
ErrorCodePlacementError ErrorCode = "placement_error" // An error during the placement occurred
3638
ErrorCodeServerAlreadyAttached ErrorCode = "server_already_attached" // The server is already attached to the resource
3739

3840
// Load Balancer related error codes.
41+
3942
ErrorCodeIPNotOwned ErrorCode = "ip_not_owned" // The IP you are trying to add as a target is not owned by the Project owner
4043
ErrorCodeSourcePortAlreadyUsed ErrorCode = "source_port_already_used" // The source port you are trying to add is already in use
4144
ErrorCodeCloudResourceIPNotAllowed ErrorCode = "cloud_resource_ip_not_allowed" // The IP you are trying to add as a target belongs to a Hetzner Cloud resource
@@ -47,15 +50,18 @@ const (
4750
ErrorCodeLoadBalancerNotAttachedToNetwork ErrorCode = "load_balancer_not_attached_to_network" // The Load Balancer is not attached to a network
4851

4952
// Network related error codes.
53+
5054
ErrorCodeIPNotAvailable ErrorCode = "ip_not_available" // The provided Network IP is not available
5155
ErrorCodeNoSubnetAvailable ErrorCode = "no_subnet_available" // No Subnet or IP is available for the Load Balancer/Server within the network
5256
ErrorCodeVSwitchAlreadyUsed ErrorCode = "vswitch_id_already_used" // The given Robot vSwitch ID is already registered in another network
5357

5458
// Volume related error codes.
59+
5560
ErrorCodeNoSpaceLeftInLocation ErrorCode = "no_space_left_in_location" // There is no volume space left in the given location
5661
ErrorCodeVolumeAlreadyAttached ErrorCode = "volume_already_attached" // Volume is already attached to a server, detach first
5762

5863
// Firewall related error codes.
64+
5965
ErrorCodeFirewallAlreadyApplied ErrorCode = "firewall_already_applied" // Firewall was already applied on resource
6066
ErrorCodeFirewallAlreadyRemoved ErrorCode = "firewall_already_removed" // Firewall was already removed from the resource
6167
ErrorCodeIncompatibleNetworkType ErrorCode = "incompatible_network_type" // The Network type is incompatible for the given resource
@@ -64,6 +70,7 @@ const (
6470
ErrorCodeFirewallResourceNotFound ErrorCode = "firewall_resource_not_found" // Resource a firewall should be attached to / detached from not found
6571

6672
// Certificate related error codes.
73+
6774
ErrorCodeCAARecordDoesNotAllowCA ErrorCode = "caa_record_does_not_allow_ca" // CAA record does not allow certificate authority
6875
ErrorCodeCADNSValidationFailed ErrorCode = "ca_dns_validation_failed" // Certificate Authority: DNS validation failed
6976
ErrorCodeCATooManyAuthorizationsFailedRecently ErrorCode = "ca_too_many_authorizations_failed_recently" // Certificate Authority: Too many authorizations failed recently
@@ -72,12 +79,13 @@ const (
7279
ErrorCodeCloudNotVerifyDomainDelegatedToZone ErrorCode = "could_not_verify_domain_delegated_to_zone" // Could not verify domain delegated to zone
7380
ErrorCodeDNSZoneNotFound ErrorCode = "dns_zone_not_found" // DNS zone not found
7481

75-
// Deprecated error codes
76-
// The actual value of this error code is limit_reached. The new error code
77-
// rate_limit_exceeded for ratelimiting was introduced before Hetzner Cloud
78-
// launched into the public. To make clients using the old error code still
79-
// work as expected, we set the value of the old error code to that of the
80-
// new error code.
82+
// Deprecated error codes.
83+
84+
// Deprecated: The actual value of this error code is limit_reached. The
85+
// new error code rate_limit_exceeded for rate limiting was introduced
86+
// before Hetzner Cloud launched into the public. To make clients using the
87+
// old error code still work as expected, we set the value of the old error
88+
// code to that of the new error code.
8189
ErrorCodeLimitReached = ErrorCodeRateLimitExceeded
8290
)
8391

0 commit comments

Comments
 (0)