-
Notifications
You must be signed in to change notification settings - Fork 13
/
error.go
46 lines (38 loc) · 820 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
// Copyright 2022 Michael Li <alimy@gility.net>. All rights reserved.
// Use of this source code is governed by Apache License 2.0 that
// can be found in the LICENSE file.
package mir
import (
"errors"
"fmt"
)
// Error indicator error's wraper
type Error interface {
error
StatusCode() int
}
type httpError struct {
error
statusCode int
}
func NewError(statusCode int, err error) Error {
return &httpError{
error: err,
statusCode: statusCode,
}
}
func Errorf(statusCode int, format string, a ...any) Error {
return &httpError{
error: fmt.Errorf(format, a...),
statusCode: statusCode,
}
}
func Errorln(statusCode int, text string) Error {
return &httpError{
error: errors.New(text),
statusCode: statusCode,
}
}
func (e *httpError) StatusCode() int {
return e.statusCode
}