-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.go
41 lines (36 loc) · 1.48 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
package http
import (
"errors"
"fmt"
)
var (
ErrInitialisingClient = errors.New("error initialising client")
ErrInitialisingRequest = errors.New("error initialising request")
ErrInvalidJSON = errors.New("invalid json")
ErrInvalidRequestHeader = errors.New("invalid request headers")
ErrInvalidURL = errors.New("invalid url")
ErrMaxRetriesExceeded = errors.New("http retries exceeded")
ErrNoResponseBody = errors.New("response body was empty")
ErrReadingResponseBody = errors.New("error reading response body")
ErrUnexpectedStatusCode = errors.New("unexpected status code")
// errors related to the mock client
ErrCannotChangeExpectations = errors.New("expectations cannot be changed")
ErrUnexpectedRequest = errors.New("unexpected request")
)
// MockExpectationsError is the error returned by ExpectationsNotMet() when one or
// more configured expectations have not been met. It wraps all errors
// representing the failed expectations.
type MockExpectationsError struct {
name string
errors []error
}
// Error implements the error interface for MockExpectationsError by returning a
// string representation of the error, presenting each wrapped error indented
// under a summary identifying the mock client to which the failures relate.
func (err MockExpectationsError) Error() string {
errs := ""
for _, err := range err.errors {
errs += fmt.Sprintf(" %s\n", err.Error())
}
return fmt.Sprintf("%s: expectations not met: [\n%s]", err.name, errs)
}