Skip to content

Nonsensical errors on connection failure #18

@hchagen

Description

@hchagen

Preflight checklist

Describe the bug

So, I'm not sure if I should report this here, as it's very minor, but if a request to OidcApiService (or probably most the APIs) fails due to a timeout or failure in dns resolving or connection refused or whatever, thus not returning a body, the error reported from the API client is

json: cannot unmarshal object into Go struct field ErrorOAuth2.error of type string

I feel like this could be greatly improved upon by simply checking the type of the error returned, or even reading the response into a buffer and checking its length before decoding - it would be nice to have a less nonsensical error message here, makes it a lot easier to debug when things fail!

Reproducing the bug

Use the SDK (I'm currently on "github.com/ory/client-go" v1.1.21), set it up towards a non-existent host - the specific call that fails for me is most often:

oryClient.OidcApi.DiscoverOidcConfiguration(oryClient.AuthCtx(ctx)).Execute()

and watch the magic unfold!

Relevant log output

2023-03-15 17:57:35.848 [    info] auth-sidecar.auth-sidecar-service-server (leafId=auth-sidecar-service-server, service.env=LOCAL, service.name=auth-sidecar, service.type=go, service.version=web@2914:257e1d77ba1c214e1b66331c9faf6899034ddfc4:origin/feat/grpc-keto) Unable to setup ory client: json: cannot unmarshal object into Go struct field ErrorOAuth2.error of type string, falling back to mock client
2023-03-15 17:57:35.929 [    info] auth-sidecar.auth-sidecar-service-server (leafId=auth-sidecar-service-server, service.env=LOCAL, service.name=auth-sidecar, service.type=go, service.version=web@2914:257e1d77ba1c214e1b66331c9faf6899034ddfc4:origin/feat/grpc-keto) Unable to setup ory client: json: cannot unmarshal object into Go struct field ErrorOAuth2.error of type string, falling back to mock client
2023-03-15 17:57:36.023 [    info] auth-sidecar.auth-sidecar-service-server (leafId=auth-sidecar-service-server, service.env=LOCAL, service.name=auth-sidecar, service.type=go, service.version=web@2914:257e1d77ba1c214e1b66331c9faf6899034ddfc4:origin/feat/grpc-keto) Unable to setup ory client: json: cannot unmarshal object into Go struct field ErrorOAuth2.error of type string, falling back to mock client


### Relevant configuration

```yml
I'm using ory cloud right now, so it's whatever we set up there, I don't think it's particularly relevant :)

Version

v1.1.21

On which operating system are you observing this issue?

Linux

In which environment are you deploying?

Ory Network

Additional Context

I think that's most of it, it should be fairly straightforward to fix, I think. Unless, of course, it's caused by the OpenAPI generator, which it very well might be!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething is not working.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions