-
Notifications
You must be signed in to change notification settings - Fork 19
/
error.go
56 lines (45 loc) · 887 Bytes
/
error.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
/*
* UpdateHub
* Copyright (C) 2017
* O.S. Systems Sofware LTDA: contato@ossystems.com.br
*
* SPDX-License-Identifier: Apache-2.0
*/
package updatehub
import "github.com/pkg/errors"
type UpdateHubErrorReporter interface {
Cause() error
IsFatal() bool
error
}
type UpdateHubError struct {
cause error
fatal bool
}
func (e *UpdateHubError) Cause() error {
return e.cause
}
func (e *UpdateHubError) IsFatal() bool {
return e.fatal
}
func (e *UpdateHubError) Error() string {
var err error
if e.fatal {
err = errors.Wrapf(e.cause, "fatal error")
} else {
err = errors.Wrapf(e.cause, "transient error")
}
return err.Error()
}
func NewFatalError(err error) UpdateHubErrorReporter {
return &UpdateHubError{
cause: err,
fatal: true,
}
}
func NewTransientError(err error) UpdateHubErrorReporter {
return &UpdateHubError{
cause: err,
fatal: false,
}
}