File: errors.go

package info (click to toggle)
golang-github-mimuret-golang-iij-dpf 0.9.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,340 kB
  • sloc: makefile: 55
file content (98 lines) | stat: -rw-r--r-- 2,126 bytes parent folder | download
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package api

import "errors"

func IsBadResponse(err error, f func(b *BadResponse) bool) bool {
	bad := &BadResponse{}
	if !errors.As(err, &bad) {
		return false
	}
	if f == nil {
		return true
	}
	return f(bad)
}

func IsStatusCode(err error, code int) bool {
	return IsBadResponse(err, func(bad *BadResponse) bool {
		return bad.IsStatusCode(code)
	})
}

func IsErrType(err error, name string) bool {
	return IsBadResponse(err, func(bad *BadResponse) bool {
		return bad.IsErrType(name)
	})
}

func IsErrMsg(err error, msg string) bool {
	return IsBadResponse(err, func(bad *BadResponse) bool {
		return bad.IsErrMsg(msg)
	})
}

func IsErrorCode(err error, code string) (bool, string) {
	var (
		res       bool
		attribute string
	)
	IsBadResponse(err, func(bad *BadResponse) bool {
		res, attribute = bad.IsErrorCode(code)
		return res
	})
	return res, attribute
}

func IsErrorCodeAttribute(err error, code string, attribute string) bool {
	return IsBadResponse(err, func(bad *BadResponse) bool {
		return bad.IsErrorCodeAttribute(code, attribute)
	})
}

func IsAuthError(err error) bool {
	return IsBadResponse(err, func(bad *BadResponse) bool {
		return bad.IsAuthError()
	})
}

func IsRequestFormatError(err error) bool {
	return IsBadResponse(err, func(bad *BadResponse) bool {
		return bad.IsRequestFormatError()
	})
}

func IsParameterError(err error) bool {
	return IsBadResponse(err, func(bad *BadResponse) bool {
		return bad.IsParameterError()
	})
}

func IsNotFound(err error) bool {
	return IsBadResponse(err, func(bad *BadResponse) bool {
		return bad.IsNotFound()
	})
}

func IsTooManyRequests(err error) bool {
	return IsBadResponse(err, func(bad *BadResponse) bool {
		return bad.IsTooManyRequests()
	})
}

func IsSystemError(err error) bool {
	return IsBadResponse(err, func(bad *BadResponse) bool {
		return bad.IsSystemError()
	})
}

func IsGatewayTimeout(err error) bool {
	return IsBadResponse(err, func(bad *BadResponse) bool {
		return bad.IsGatewayTimeout()
	})
}

func IsInvalidSchema(err error) bool {
	return IsBadResponse(err, func(bad *BadResponse) bool {
		return bad.IsInvalidSchema()
	})
}