/
resolver.go
72 lines (59 loc) · 1.89 KB
/
resolver.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
67
68
69
70
71
72
// Copyright (c) IOTIC LABS LIMITED. All rights reserved. Licensed under the Apache License, Version 2.0.
package register
import (
"context"
"crypto/ecdsa"
"errors"
)
// ResolverClient resolver client interface
type ResolverClient interface {
// GetDocument fetch a document from the resolver by DID identifier
GetDocument(ctx context.Context, documentID string) (*RegisterDocument, error)
// RegisterDocument registers a document in the resolver.
RegisterDocument(ctx context.Context, doc *RegisterDocument, privateKey *ecdsa.PrivateKey, issuer *Issuer) error
}
// ResolverErrType ResolverErrType
type ResolverErrType int
const (
// ConfError Resolver configuration error type
ConfError ResolverErrType = iota
// ConnectionError Resolver connection error type
ConnectionError
// ServerError Resolver server error type
ServerError
// NotFound Resolver did not found error type
NotFound
)
// ResolverError type, implements the error interface
type ResolverError struct {
err error
errType ResolverErrType
}
// NewResolverError Create a new error (For tests)
func NewResolverError(err error, errType ResolverErrType) error {
return &ResolverError{err: err, errType: errType}
}
// Error returns the representation
func (r ResolverError) Error() string {
if r.err == nil {
return "resolver error"
}
return r.err.Error()
}
// ErrorType returns the error type
func (r ResolverError) ErrorType() ResolverErrType {
return r.errType
}
// Err returns the err
func (r ResolverError) Err() error {
return r.err
}
// IsResolverError returns true if the provided error is of type ResolverError
func IsResolverError(err error) bool {
_, ok := err.(*ResolverError)
return ok
}
// IsContextError returns true if the provided error is of type context.Canceled or context.DeadlineExceeded
func IsContextError(err error) bool {
return errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded)
}