-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
66 lines (53 loc) · 2.18 KB
/
errors.go
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package fgax
import (
"errors"
"fmt"
)
var (
// ErrFGAMissingHost is returned when a host is not provided
ErrFGAMissingHost = errors.New("invalid OpenFGA config: missing host")
// ErrMissingRelation is returned when a relation is empty in a tuple creation
ErrMissingRelation = errors.New("unable to create tuple, missing relation")
// ErrInvalidAccessCheck is returned when a field required to check a tuple is empty
ErrInvalidAccessCheck = errors.New("unable to check tuple, missing required field")
// ErrMissingObject is returned when a object is empty in a tuple creation
ErrMissingObject = errors.New("unable to create tuple, missing object")
// ErrMissingObjectOnDeletion is returned when a object is empty in a tuple deletion
ErrMissingObjectOnDeletion = errors.New("unable to delete tuple, missing object")
// ErrFailedToTransformModel is returned when the FGA model cannot be transformed to JSON
ErrFailedToTransformModel = errors.New("failed to transform fga model")
)
// InvalidEntityError is returned when an invalid openFGA entity is configured
type InvalidEntityError struct {
EntityRepresentation string
}
// Error returns the InvalidEntityError in string format
func (e *InvalidEntityError) Error() string {
return fmt.Sprintf("invalid entity representation: %s", e.EntityRepresentation)
}
func newInvalidEntityError(s string) *InvalidEntityError {
return &InvalidEntityError{
EntityRepresentation: s,
}
}
// WritingTuplesError is returned when an error is returned writing a relationship tuple
type WritingTuplesError struct {
User string
Relation string
Object string
Operation string
ErrorResponse error
}
// Error returns the InvalidEntityError in string format
func (e *WritingTuplesError) Error() string {
return fmt.Sprintf("failed to %s tuple to OpenFGA store: (user: %s; relation: %s; object: %s), error: %v", e.Operation, e.User, e.Relation, e.Object, e.ErrorResponse.Error())
}
func newWritingTuplesError(user, relation, object, operation string, err error) *WritingTuplesError {
return &WritingTuplesError{
User: user,
Relation: relation,
Object: object,
Operation: operation,
ErrorResponse: err,
}
}