-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Read APIError response body #121
Comments
@casualjim any thoughts on this? |
I'm having problem with this also. As an outsider of this project, it seems like the |
you have to provide the error datastructure in the definitions, so that it gets picked up the mixin tool lets you edit a spec by deep merging another one, in case the spec isn't under your control. |
Ignore my ranting, my problem is actually 'just' that of @mxinden . If I just print the error by the APIError's own error function, I get this: When I @mxinden 's approach to explicitly read the body of the |
I am facing the same issue, reading the response body is a must in my application. Is there any solution available ? |
@deeptibaghel There is no problem reading a response body, including error responses. Like this: responses:
badRequest:
description: client error in request
schema:
type: object
properties:
errorMessage:
type: string If you expect a generic object, do this like: responses:
badRequest:
description: client error in request
schema:
type: object
additionalProperties: true |
Thanks @fredbi , so my swagger yaml file should have it and then the client will generate methods to read it right ? |
Yes. You just have to insert some type assertion switch on the returned Something like this (example without switch and without actually using the content): if _, notFound := erp.(*operations.GetRolesByIDRoleIDNotFound); notFound {
// looks like this has disappeared since last fetched: skip
continue
} |
Many Thanks @fredbi |
I make a request via a client generated based on a swagger spec generated via the goswagger.io project with an invalid json property. The back-end returns a HTTP 422 with details in the response body. Reading the response body is crucial to debug the problem.
go-openapi/runtime/client/runtime.go.Submit()
callsreadResponse.ReadResponse
which returns anAPIError
with the response body embedded:runtime/client/runtime.go
Line 422 in 231d787
runtime/client_response.go
Lines 55 to 59 in 231d787
Problem is, that this embedded response body is closed via a
defer
ingo-openapi/runtime/client/runtime.go.Submit()
:runtime/client/runtime.go
Line 395 in 231d787
Thereby casting the error and reading the response body later on fails with
http: read on closed response body
:How can I access the APIError response body? Might it be possible to embed the body as a string inside the APIError? Let me know if you need more info.
The text was updated successfully, but these errors were encountered: