-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patherrors.go
More file actions
44 lines (37 loc) · 1000 Bytes
/
Copy patherrors.go
File metadata and controls
44 lines (37 loc) · 1000 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package gorthanc
import "fmt"
// HTTPError represents an HTTP error response from the Orthanc server
type HTTPError struct {
StatusCode int
Status string
Body string
}
func (e *HTTPError) Error() string {
return fmt.Sprintf("HTTP %d: %s - %s", e.StatusCode, e.Status, e.Body)
}
// IsHTTPError checks if an error is an HTTPError
func IsHTTPError(err error) bool {
_, ok := err.(*HTTPError)
return ok
}
// IsNotFound checks if an error is a 404 Not Found error
func IsNotFound(err error) bool {
if httpErr, ok := err.(*HTTPError); ok {
return httpErr.StatusCode == 404
}
return false
}
// IsUnauthorized checks if an error is a 401 Unauthorized error
func IsUnauthorized(err error) bool {
if httpErr, ok := err.(*HTTPError); ok {
return httpErr.StatusCode == 401
}
return false
}
// IsForbidden checks if an error is a 403 Forbidden error
func IsForbidden(err error) bool {
if httpErr, ok := err.(*HTTPError); ok {
return httpErr.StatusCode == 403
}
return false
}