You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
this is ok when service response code is 200 and the responseApi is getUserOk struct。but when the response code is 400 or 500,how can i get the ErrorResponse?i sow when resp code is non-200, the ReadResponse method(called in Submit)only panic some msg instead of return the expected ErrorResponse
result, err := a.transport.Submit(op)
if err != nil {
return nil, err
}
success, ok := result.(*ModifyUserOK)
if ok {
return success, nil
}
// unexpected success response
// safeguard: normally, absent a default response, unknown success responses return an error above: so this is a codegen issue
msg := fmt.Sprintf("unexpected success response for modifyUser: API contract not enforced by server. Client expected to get an error, but got: %T", result)
panic(msg)
so how can i get expected ErrorResponse ?
Swagger specification
latest, 0.30
Steps to reproduce
Environment
swagger version: x.x.x
go version: 1.17.4
OS: centos 7.2 x86_64
responseApi, err := sdk.SdkClient.User.GetUser(req, nil)
if err != nil {
switch errResponse := err.(type) {
case *sdkModels.ErrorResponse:
...
}
}
it show errors as:
err (variable of type error) cannot have dynamic type *models.ErrorResponse (missing method Error)
how can i fix it?
###############
the ErrorResponse swagger defined as:
// unit err response for non 200
// swagger:response ErrorResponse
type ErrorResponse struct {
//In: body
Body struct {
Err controllers.ErrorResponse `json:"error"`
}
}
and controllers.ErrorResponse defined as:
type ErrorResponse struct {
Code int `json:"code"`
Message string `json:"message"`
Status string `json:"status"`
}
what ErrorResponse in generated code like this:
// ErrorResponse error response
//
// swagger:model ErrorResponse
type ErrorResponse struct {
// code
Code int64 `json:"code,omitempty"`
// message
Message string `json:"message,omitempty"`
// status
Status string `json:"status,omitempty"`
}
the ErrorResponse type has Validate,ContextValidate,MarshalBinary,UnmarshalBinary but missing Error() method.
even if i add Error() method on controllers.ErrorResponse,the Error() method can't show in generated swagger.yml,of course the sdkModels.ErrorResponse type missing Error() method in the generated sdk code. then the error pasted in first occures. so how can i fix it?
Activity
casualjim commentedon Nov 19, 2022
you can typeswitch on the error
minping-dream commentedon Nov 21, 2022
thanks for your reply, however when i did so:
it show errors as:
how can i fix it?
###############
the ErrorResponse swagger defined as:
and controllers.ErrorResponse defined as:
what ErrorResponse in generated code like this:
the ErrorResponse type has Validate,ContextValidate,MarshalBinary,UnmarshalBinary but missing Error() method.
even if i add Error() method on controllers.ErrorResponse,the Error() method can't show in generated swagger.yml,of course the sdkModels.ErrorResponse type missing Error() method in the generated sdk code. then the error pasted in first occures. so how can i fix it?