forked from pinguo/pgo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathException.go
38 lines (31 loc) · 822 Bytes
/
Exception.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
package pgo
import (
"fmt"
)
// NewException create new exception with status and message
func NewException(status int, msg ...interface{}) *Exception {
message := ""
if len(msg) == 1 {
message = msg[0].(string)
} else if len(msg) > 1 {
message = fmt.Sprintf(msg[0].(string), msg[1:]...)
}
return &Exception{status, message}
}
// Exception panic as exception
type Exception struct {
status int
message string
}
// GetStatus get exception status code
func (e *Exception) GetStatus() int {
return e.status
}
// GetMessage get exception message string
func (e *Exception) GetMessage() string {
return e.message
}
// Error implement error interface
func (e *Exception) Error() string {
return fmt.Sprintf("exception: %d, message: %s", e.status, e.message)
}