This repository has been archived by the owner on Jul 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patherror.go
71 lines (60 loc) · 1.92 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
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
// Copyright 2017-2018 Vasiliy Vasilyuk. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package blockchair
import (
"errors"
"net/http"
)
// Errors it is a set of errors returned when working with the package.
var (
ErrAIW = errors.New(Package + ": address is wrong")
ErrCGD = errors.New(Package + ": cannot get data on url")
ErrCRR = errors.New(Package + ": could not read answer response")
ErrIRS = errors.New(Package + ": incorrect response status")
ErrRPE = errors.New(Package + ": response parsing error")
)
// Error data structure describing the error.
type Error struct {
// Address wrong address.
Address *string
// ErrMain error information from the standard package error set.
ErrMain error
// ErrExec information about the error that occurred during
// the operation of the standard library or external packages.
ErrExec error
// Response http response.
Response *http.Response
}
// Error compatibility with error interface.
func (e Error) Error() string {
return e.ErrMain.Error()
}
// NewError creates a new Error instance.
func NewError(errorMain error, errorExec error, response *http.Response, address *string) *Error {
if errorMain == nil {
return nil
}
return &Error{
ErrMain: errorMain,
ErrExec: errorExec,
Response: response,
Address: address,
}
}
// err build error helper.
func (c *Client) err(errorMain error) error {
return NewError(errorMain, nil, nil, nil)
}
// err2 build error helper.
func (c *Client) err2(errorMain error, errorExec error) error {
return NewError(errorMain, errorExec, nil, nil)
}
// err3 build error helper.
func (c *Client) err3(errorMain error, errorExec error, response *http.Response) error {
return NewError(errorMain, errorExec, response, nil)
}
// err4 build error helper.
func (c *Client) err4(errorMain error, response string) error {
return NewError(errorMain, nil, nil, &response)
}