-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy patherrors.go
More file actions
40 lines (34 loc) · 1.03 KB
/
errors.go
File metadata and controls
40 lines (34 loc) · 1.03 KB
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
// Copyright (c) 2017, 2019 Tim Heckman
// Use of this source code is governed by the MIT License that can be found in
// the LICENSE file at the root of this repository.
package ipdata
// Error represents an error returned from the ipdata.co API. This error value
// will be used whenever the HTTP request to the API completed, but the HTTP
// status code indicated failure. The Error() method will return the JSON
// message sent by the API, if present, and Code() returns the numeric HTTP
// status code.
type Error struct {
m string
c int
i int
}
func newError(message string, code int) Error {
return Error{
m: message,
c: code,
i: -1,
}
}
// Error returns the message JSON field sent from the ipdata.co API. This also
// satisfies the error interface.
func (e Error) Error() string {
return e.m
}
// Code returns the HTTP Status code returned from the ipdata.co API.
func (e Error) Code() int {
return e.c
}
// Index returns the index first item in a BulkLookup that encountered an error.
func (e Error) Index() int {
return e.i
}