Skip to content

Commit

Permalink
op
Browse files Browse the repository at this point in the history
  • Loading branch information
gif001 committed Jan 22, 2025
1 parent ab82997 commit 4af3f5f
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion goio/server/server_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package goserver
import (
"encoding/json"
"fmt"
goerror "github.com/gif-gif/go.io/go-error"
goutils "github.com/gif-gif/go.io/go-utils"
"github.com/go-playground/validator/v10"
"github.com/gogf/gf/util/gconv"
"github.com/samber/lo"

"strings"
Expand Down Expand Up @@ -90,7 +92,7 @@ func SuccessResponse(data any) *Response {
}

// 便捷方法: 快速创建错误响应
func ErrorResponse(errorCode string, errorMessage string, showType ...uint32) *Response {
func ErrorResponseX(errorCode string, errorMessage string, showType ...uint32) *Response {
return NewResponseBuilder().
WithSuccess(false).
WithErrorCode(errorCode).
Expand All @@ -99,6 +101,17 @@ func ErrorResponse(errorCode string, errorMessage string, showType ...uint32) *R
Build()
}

func ErrorResponse(err *goerror.CodeError) *Response {
return NewResponseBuilder().
WithSuccess(false).
WithErrorCode(gconv.String(err.GetErrCode())).
WithErrorMessage(err.GetErrMsg()).
WithShowType(err.GetShowType()).
WithTraceId(err.GetTraceId()).
WithHost(err.GetHost()).
Build()
}

func (rsp *Response) Copy() *Response {
r := NewResponseBuilder().
WithSuccess(rsp.Success).
Expand Down

0 comments on commit 4af3f5f

Please sign in to comment.