/
errors.go
85 lines (69 loc) · 3.55 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
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
package deeplclient
import (
"fmt"
"strconv"
)
// UnwrappedApiResponseCodeErr represents an error if the API server returns an unexpected status code.
type UnwrappedApiResponseCodeErr int
// Error returns a compact version of all error information in order to implement the error interface.
func (err UnwrappedApiResponseCodeErr) Error() string {
return fmt.Sprintf("server returned unexpected status code: %d", err)
}
// KnownRequestErrData contains the standard data which can be parsed from json for every error.
type KnownRequestErrData struct {
// Message holds the error message returned by the server.
Message string `json:"message"`
}
// WrongRequestErr indicates the response code 400 returned by the remote API server and contains the error message.
type WrongRequestErr struct {
*KnownRequestErrData
}
// Error returns a compact version of all error information in order to implement the error interface.
func (err *WrongRequestErr) Error() string {
return fmt.Sprintf("server returned status code 400 (wrong request): %s", strconv.Quote(err.Message))
}
// AuthFailedErr indicates the response code 403 returned by the remote API server and contains the error message.
// Normally this error occurs if an invalid auth token was provided.
type AuthFailedErr struct {
*KnownRequestErrData
}
// Error returns a compact version of all error information in order to implement the error interface.
func (err *AuthFailedErr) Error() string {
return fmt.Sprintf("server returned status code 403 (autorization failed)")
}
// RequestEntityTooLargeErr indicates the response code 413 returned by the remote API server and contains the error message.
// Normally this error occurs if the request size exceeds the current limit.
type RequestEntityTooLargeErr struct {
*KnownRequestErrData
}
// Error returns a compact version of all error information in order to implement the error interface.
func (err *RequestEntityTooLargeErr) Error() string {
return fmt.Sprintf("server returned status code 413 (request entity too large): %s", strconv.Quote(err.Message))
}
// TooManyRequestsErr indicates the response code 429 returned by the remote API server and contains the error message.
// Normally this error occurs if too many requests have been sent in a short amount of time.
type TooManyRequestsErr struct {
*KnownRequestErrData
}
// Error returns a compact version of all error information in order to implement the error interface.
func (err *TooManyRequestsErr) Error() string {
return fmt.Sprintf("server returned status code 429 (too many request): %s", strconv.Quote(err.Message))
}
// QuotaExceededErr indicates the response code 403 returned by the remote API server and contains the error message.
// Normally this error occurs if the character limit has been reached.
type QuotaExceededErr struct {
*KnownRequestErrData
}
// Error returns a compact version of all error information in order to implement the error interface.
func (err *QuotaExceededErr) Error() string {
return fmt.Sprintf("server returned status code 456 (quota exceeded): %s", strconv.Quote(err.Message))
}
// NotFoundErr indicates the response code 404 returned by the remote API server and contains the error message.
// Normally this error occurs if an undefined API endpoint of an undefined document status/result is requested.
type NotFoundErr struct {
*KnownRequestErrData
}
// Error returns a compact version of all error information in order to implement the error interface.
func (err *NotFoundErr) Error() string {
return fmt.Sprintf("server returned status code 404 (not found): %s", strconv.Quote(err.Message))
}