Skip to content

Commit ad5e007

Browse files
committed
save
0 parents  commit ad5e007

File tree

5 files changed

+84
-0
lines changed

5 files changed

+84
-0
lines changed

error.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package errorx
2+
3+
import (
4+
"fmt"
5+
)
6+
7+
type Error interface {
8+
Error() string // error interface
9+
String() string // Stringer interface
10+
11+
Code() int
12+
Message() string
13+
}
14+
15+
type ErrorPayload struct {
16+
CodePayload int `json:"code"`
17+
MessagePayload string `json:"message"`
18+
}
19+
20+
func New(code int, message string) Error {
21+
return ErrorPayload{
22+
CodePayload: code,
23+
MessagePayload: message,
24+
}
25+
}
26+
27+
func NewFromErr(code int, err error) Error {
28+
return ErrorPayload{
29+
CodePayload: code,
30+
MessagePayload: err.Error(),
31+
}
32+
}
33+
34+
func NewErrorPayloadFromError(errx Error) *ErrorPayload {
35+
return &ErrorPayload{
36+
CodePayload: errx.Code(),
37+
MessagePayload: errx.Message(),
38+
}
39+
}
40+
41+
func (thisRef ErrorPayload) Code() int {
42+
return thisRef.CodePayload
43+
}
44+
45+
func (thisRef ErrorPayload) Message() string {
46+
return thisRef.MessagePayload
47+
}
48+
49+
func (thisRef ErrorPayload) String() string {
50+
return fmt.Sprintf("message: %s, code: %d", thisRef.MessagePayload, thisRef.CodePayload)
51+
}
52+
53+
func (thisRef ErrorPayload) Error() string {
54+
return thisRef.String()
55+
}

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/remoteit/systemkit-errorx
2+
3+
go 1.13

go.sum

Whitespace-only changes.

license

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
MIT License
2+
-----------
3+
4+
Copyright (c) 2021 remote.it (https://remote.it)
5+
6+
Permission is hereby granted, free of charge, to any person
7+
obtaining a copy of this software and associated documentation
8+
files (the "Software"), to deal in the Software without
9+
restriction, including without limitation the rights to use,
10+
copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the
12+
Software is furnished to do so, subject to the following
13+
conditions:
14+
15+
The above copyright notice and this permission notice shall be
16+
included in all copies or substantial portions of the Software.
17+
18+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25+
OTHER DEALINGS IN THE SOFTWARE.

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# remote.it errorx

0 commit comments

Comments
 (0)