feat: new error response remove dup
This commit is contained in:
@ -70,7 +70,19 @@ func NewTextResponse(text string) *Response {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewJsonResponse(data map[string]string) (*Response, error) {
|
func NewErrorResponse(err error) *Response {
|
||||||
|
return &Response{
|
||||||
|
StatusCode: STATUS_INTERNALERR,
|
||||||
|
Headers: make(map[string]string),
|
||||||
|
Format: DataFormat{
|
||||||
|
Format: DF_TEXT,
|
||||||
|
Encoding: E_UTF8,
|
||||||
|
},
|
||||||
|
Payload: []byte(err.Error()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewJsonResponse(data any) (*Response, error) {
|
||||||
jsonBytes, err := json.Marshal(data)
|
jsonBytes, err := json.Marshal(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -87,18 +99,6 @@ func NewJsonResponse(data map[string]string) (*Response, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewErrorResponse(err error) *Response {
|
|
||||||
return &Response{
|
|
||||||
StatusCode: STATUS_INTERNALERR,
|
|
||||||
Format: DataFormat{
|
|
||||||
Format: DF_TEXT,
|
|
||||||
Encoding: E_UTF8,
|
|
||||||
},
|
|
||||||
Headers: map[string]string{},
|
|
||||||
Payload: []byte(err.Error()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (res *Response) ToPacket() *Packet {
|
func (res *Response) ToPacket() *Packet {
|
||||||
headers := make(map[string]string)
|
headers := make(map[string]string)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user