-
Notifications
You must be signed in to change notification settings - Fork 2
/
errors.go
44 lines (39 loc) · 1.11 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
package nodeless
import (
"fmt"
"strings"
)
var (
ErrInvoiceNotFound = fmt.Errorf("invoice not found")
ErrDonationPageNotFound = fmt.Errorf("donation page not found")
ErrWebhookNotFound = fmt.Errorf("webhook not found")
ErrPaywallRequestNotFound = fmt.Errorf("paywall request not found")
ErrPaywallNotFound = fmt.Errorf("paywall not found")
ErrNotFound = fmt.Errorf("not found")
// Config
ErrMissingAPIKey = fmt.Errorf("missing api key")
)
// parseError returns strongly typed errors from api error messages
func parseError(msg string) error {
msg = strings.ToLower(msg)
// Resource not found
if strings.HasPrefix(msg, "no query results") {
if strings.Contains(msg, "storeinvoice") {
return ErrInvoiceNotFound
}
if strings.Contains(msg, "donationpage") {
return ErrDonationPageNotFound
}
if strings.Contains(msg, "webhook") {
return ErrWebhookNotFound
}
if strings.Contains(msg, "paywallrequest") {
return ErrPaywallRequestNotFound
}
if strings.Contains(msg, "paywall") {
return ErrPaywallNotFound
}
}
// Unknown error
return fmt.Errorf(msg)
}