forked from psanford/finance-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.go
40 lines (33 loc) · 1.1 KB
/
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
package finance
import (
"fmt"
)
const (
// apiErrorCode denotes an error caught by finance-go
// stemming from invalid user inputs.
apiErrorCode = "api-error"
// remoteErrorCode denotes an error
// communicated in a reponse from a
// remote api source.
remoteErrorCode = "remote-error"
)
// CreateArgumentError returns an error
// with a message about missing arguments.
func CreateArgumentError() error {
return fmt.Errorf("code: %s, detail: %s", apiErrorCode, "missing function argument")
}
// CreateChartTimeError returns an error
// with a message improper chart arguments.
func CreateChartTimeError() error {
return fmt.Errorf("code: %s, detail: %s", apiErrorCode, "start time cannot be more recent than end time")
}
// CreateRemoteError returns an error
// with a message about a remote api problem.
func CreateRemoteError(e error) error {
return fmt.Errorf("code: %s, detail: %w", remoteErrorCode, e)
}
// CreateRemoteErrorS returns an error
// with a message about a remote api problem.
func CreateRemoteErrorS(str string) error {
return fmt.Errorf("code: %s, detail: %s", remoteErrorCode, str)
}