-
Notifications
You must be signed in to change notification settings - Fork 1
/
error.go
50 lines (39 loc) · 989 Bytes
/
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
// Copyright 2018 DataArt. All rights reserved.
// Use of this source code is governed by an Apache-style
// license that can be found in the LICENSE file.
package devicehive_go
import "github.com/devicehive/devicehive-go/internal/transport"
func newError(err error) *Error {
if err == nil {
return nil
}
switch err.(type) {
case *transport.Error:
return newTransportErr(err.(*transport.Error))
default:
return &Error{ServiceErr, err.Error()}
}
}
func newJSONErr(err error) *Error {
return &Error{name: InvalidResponseErr, reason: "data is not valid JSON string: " + err.Error()}
}
func newTransportErr(err *transport.Error) *Error {
return &Error{name: err.Name(), reason: err.Error()}
}
type Error struct {
name string
reason string
}
// Method serves as name getter to classify the type of error
func (e *Error) Name() string {
if e == nil {
return ""
}
return e.name
}
func (e *Error) Error() string {
if e == nil {
return ""
}
return e.reason
}