forked from eclipse-iofog/iofog-go-sdk
/
errors.go
119 lines (99 loc) · 2.27 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
* *******************************************************************************
* * Copyright (c) 2019 Edgeworx, Inc.
* *
* * This program and the accompanying materials are made available under the
* * terms of the Eclipse Public License v. 2.0 which is available at
* * http://www.eclipse.org/legal/epl-2.0
* *
* * SPDX-License-Identifier: EPL-2.0
* *******************************************************************************
*
*/
package apps
import (
"fmt"
)
type Error struct {
msg string
}
func NewError(msg string) (err *Error) {
err = new(Error)
err.msg = msg
return err
}
func (err *Error) Error() string {
return err.msg
}
// NotFoundError export
type NotFoundError struct {
msg string
}
// NewNotFoundError export
func NewNotFoundError(msg string) (err *NotFoundError) {
err = new(NotFoundError)
err.msg = msg
return err
}
// Error export
func (err *NotFoundError) Error() string {
return fmt.Sprintf("Unknown resource error\n%s", err.msg)
}
// ConflictError export
type ConflictError struct {
msg string
}
// NewConflictError export
func NewConflictError(msg string) (err *ConflictError) {
err = new(ConflictError)
err.msg = msg
return err
}
// Error export
func (err *ConflictError) Error() string {
return fmt.Sprintf("Resource conflict error\n%s", err.msg)
}
// InputError export
type InputError struct {
message string
}
// NewInputError export
func NewInputError(message string) (err *InputError) {
err = new(InputError)
err.message = message
return err
}
// Error export
func (err *InputError) Error() string {
return "User input error\n" + err.message
}
// InternalError export
type InternalError struct {
message string
}
// NewInternalError export
func NewInternalError(message string) (err *InternalError) {
err = new(InternalError)
err.message = message
return err
}
// Error export
func (err *InternalError) Error() string {
return "Unexpected internal behaviour\n" + err.message
}
// HTTPError export
type HTTPError struct {
message string
Code int
}
// NewHTTPError export
func NewHTTPError(message string, code int) (err *HTTPError) {
err = new(HTTPError)
err.message = message
err.Code = code
return err
}
// Error export
func (err *HTTPError) Error() string {
return "Unexpected HTTP response\n" + err.message
}