-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.go
More file actions
49 lines (44 loc) · 1.21 KB
/
error.go
File metadata and controls
49 lines (44 loc) · 1.21 KB
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
45
46
47
48
49
package ipa
import (
"errors"
"fmt"
)
var (
ErrNotFound = errors.New("ipa: not found")
ErrAlreadyExists = errors.New("ipa: already exists")
ErrDuplicate = errors.New("ipa: duplicate entry")
ErrValidation = errors.New("ipa: validation error")
ErrACIError = errors.New("ipa: permission denied")
ErrExecution = errors.New("ipa: execution error")
ErrConversion = errors.New("ipa: conversion error")
ErrNetwork = errors.New("ipa: network error")
ErrUnknown = errors.New("ipa: unknown error")
)
type IPAError struct {
Code int `json:"code"`
Name string `json:"name"`
Message string `json:"message"`
}
func (e *IPAError) Error() string {
return fmt.Sprintf("ipa %s (%d): %s", e.Name, e.Code, e.Message)
}
func (e *IPAError) Unwrap() error {
switch e.Name {
case "NotFound":
return ErrNotFound
case "DuplicateEntry", "DuplicateEntryError":
return ErrDuplicate
case "AlreadyExists":
return ErrAlreadyExists
case "ACIError", "AuthorizationError":
return ErrACIError
case "ValidationError", "RequirementError", "ConversionError":
return ErrValidation
case "ExecutionError":
return ErrExecution
case "NetworkError":
return ErrNetwork
default:
return ErrUnknown
}
}