improve error information for package goai

This commit is contained in:
John Guo
2021-10-06 15:03:00 +08:00
parent 9ed79e9e86
commit 18ede3ae1f
4 changed files with 13 additions and 11 deletions

View File

@ -7,6 +7,7 @@
package ghttp
import (
"context"
"github.com/gogf/gf/internal/intlog"
"github.com/gogf/gf/protocol/goai"
"github.com/gogf/gf/text/gstr"
@ -18,6 +19,7 @@ func (s *Server) initOpenApi() {
return
}
var (
ctx = context.TODO()
err error
method string
)
@ -37,7 +39,7 @@ func (s *Server) initOpenApi() {
Object: item.Handler.Info.Value.Interface(),
})
if err != nil {
panic(err)
s.Logger().Fatalf(ctx, `%+v`, err)
}
}
}

View File

@ -59,7 +59,7 @@ func (oai *OpenApiV3) newParameterRefWithStructMethod(field *structs.Field) (*Pa
if len(tagMap) > 0 {
err := gconv.Struct(tagMap, parameter)
if err != nil {
return nil, gerror.WrapCodef(gcode.CodeInternalError, err, `mapping struct tags to Parameter failed`)
return nil, gerror.WrapCode(gcode.CodeInternalError, err, `mapping struct tags to Parameter failed`)
}
}
// Required for path parameter.

View File

@ -97,9 +97,9 @@ func (oai *OpenApiV3) addPath(in addPathInput) error {
in.Path = gmeta.Get(inputObject.Interface(), TagNamePath).String()
}
if in.Path == "" {
return gerror.NewCode(
return gerror.NewCodef(
gcode.CodeMissingParameter,
`missing necessary path parameter "%s" for input struct "%s"`,
`missing necessary path parameter "%s" for input struct "%s", missing tag in attribute Meta?`,
TagNamePath, inputStructTypeName,
)
}
@ -108,10 +108,10 @@ func (oai *OpenApiV3) addPath(in addPathInput) error {
in.Method = gmeta.Get(inputObject.Interface(), TagNameMethod).String()
}
if in.Method == "" {
return gerror.NewCode(
return gerror.NewCodef(
gcode.CodeMissingParameter,
`missing necessary method parameter "%s" for input struct "%s"`,
TagNamePath, inputStructTypeName,
`missing necessary method parameter "%s" for input struct "%s", missing tag in attribute Meta?`,
TagNameMethod, inputStructTypeName,
)
}
@ -121,10 +121,10 @@ func (oai *OpenApiV3) addPath(in addPathInput) error {
if len(inputMetaMap) > 0 {
if err := gconv.Struct(inputMetaMap, &path); err != nil {
return gerror.WrapCodef(gcode.CodeInternalError, err, `mapping struct tags to Path failed`)
return gerror.WrapCode(gcode.CodeInternalError, err, `mapping struct tags to Path failed`)
}
if err := gconv.Struct(inputMetaMap, &operation); err != nil {
return gerror.WrapCodef(gcode.CodeInternalError, err, `mapping struct tags to Operation failed`)
return gerror.WrapCode(gcode.CodeInternalError, err, `mapping struct tags to Operation failed`)
}
}
// Request.
@ -174,7 +174,7 @@ func (oai *OpenApiV3) addPath(in addPathInput) error {
)
if len(outputMetaMap) > 0 {
if err := gconv.Struct(outputMetaMap, &response); err != nil {
return gerror.WrapCodef(gcode.CodeInternalError, err, `mapping struct tags to Response failed`)
return gerror.WrapCode(gcode.CodeInternalError, err, `mapping struct tags to Response failed`)
}
}
// Supported mime types of response.

View File

@ -34,7 +34,7 @@ func (oai *OpenApiV3) newSchemaRefWithGolangType(golangType reflect.Type, tagMap
)
if len(tagMap) > 0 {
if err := gconv.Struct(tagMap, schema); err != nil {
return nil, gerror.WrapCodef(gcode.CodeInternalError, err, `mapping struct tags to Schema failed`)
return nil, gerror.WrapCode(gcode.CodeInternalError, err, `mapping struct tags to Schema failed`)
}
}
schemaRef.Value = schema