Skip to content

Commit

Permalink
add error code definition
Browse files Browse the repository at this point in the history
  • Loading branch information
panfeng authored and panfeng committed Aug 17, 2023
1 parent 4369cba commit e7c4fe3
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions edge/pkg/appsd/model/err.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package model

import "fmt"

type Error struct {
Status int `json:"-"`
Code string `json:"code"`
Message string `json:"msg"`
}

func (e *Error) Error() string {
return fmt.Sprintf("error:status=%v code=%s, message=%s", e.Status, e.Code, e.Message)
}

func New(status int, code, message string) *Error {
return &Error{
Status: status,
Code: code,
Message: message,
}
}

var (
Success = New(200, "1000", "Success")
ErrInvalidParam = New(400, "1002", "Invalid parameter")
ErrCertEmpty = New(403, "1112", "Domain has no cert")
ErrRequestMethod = New(405, "1113", "Request method error")
ErrInternalServer = New(500, "1001", "Internal server error")
ErrJsonUnmarshal = New(500, "1107", "Json unmarshal error")
ErrFormatResponse = New(500, "1108", "Format http response error")
)

0 comments on commit e7c4fe3

Please sign in to comment.