Skip to content

Commit

Permalink
fix: initial err code
Browse files Browse the repository at this point in the history
  • Loading branch information
ShiningRush committed May 18, 2023
1 parent 0d5ce92 commit 3137319
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
23 changes: 22 additions & 1 deletion droplet.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ var (
&codec.MultipartForm{},
&codec.Empty{},
},
ErrSetting: ErrSetting{
DefaultErrCode: data.ErrCodeInternal,
ValidateErrCode: data.ErrCodeValidate,
},
}
)

Expand All @@ -36,5 +40,22 @@ type GlobalOpt struct {
Orchestrator core.Orchestrator
Codec []codec.Interface
TrafficLogOpt *middleware.TrafficLogOpt
DefaultErrCode int
ErrSetting ErrSetting
}

type ErrSetting struct {
DefaultErrCode int
ValidateErrCode int
}

func AppendCodec(code codec.Interface) {
Option.Codec = append(Option.Codec, code)
}

func WithDefaultErrCode(code int) {
Option.ErrSetting.DefaultErrCode = code
}

func WithValidateErrCode(code int) {
Option.ErrSetting.ValidateErrCode = code
}
3 changes: 2 additions & 1 deletion wrapper/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,15 @@ func HandleHttpInPipeline(input HandleHttpInPipelineInput) {
HeaderKeyRequestID: droplet.Option.HeaderKeyRequestID,
})).
Add(middleware.NewRespReshapeMiddleware(droplet.Option.ResponseNewFunc, middleware.HttpRespReshapeOpt{
DefaultErrCode: droplet.Option.DefaultErrCode,
DefaultErrCode: droplet.Option.ErrSetting.DefaultErrCode,
})).
Add(middleware.NewHttpInputMiddleWare(middleware.HttpInputOption{
PathParamsFunc: input.PathParamsFunc,
InputType: opt.inputType,
IsReadFromBody: opt.isReadFromBody,
DisableUnmarshalBody: opt.disableUnmarshalBody,
Codecs: droplet.Option.Codec,
ValidateErrCode: droplet.Option.ErrSetting.ValidateErrCode,
})).
Add(middleware.NewTrafficLogMiddleware(trafficOpt)).
SetOrchestrator(opt.orchestrator).
Expand Down

0 comments on commit 3137319

Please sign in to comment.