Skip to content

API errors hide the server's reason: generated client shows only the status (or a oneOf decode error for a bad API key) #35

Backlog

Description

@DzmitryHumianiuk

Problem

When ReportPortal rejects a request, it says why in the response body. goRP loses that on the way to the user, and the two clients in pkg/gorp lose it differently.

Observed against a live ReportPortal 6 server with goRP at 5a832e4 (the branch of PR #33). err.Error() of read-only GET requests:

Case Generated client (client.LaunchAPI…) Resty helpers (client.GetLaunchesByFilterString)
Wrong API key, 401 data failed to match schemas in oneOf(SaveAnalyticsSettings1401Response): json: cannot unmarshal object into Go value of type string status code error: 401\n{\n "error_description" : "Invalid access token",\n "error" : "invalid_token"\n}
Launch 999999999 / project doesn't exist, 404 404 Not Found status code error: 404\n{"errorCode":4040,"message":"Project 'no-such-project-gorp' not found. Did you use correct project name?"}
page.sort=noSuchField,asc, 400 400 Bad Request status code error: 400\n{"errorCode":40012,"message":"Sorting parameter noSuchField is not defined"}
Host with a path that lands on the UI (https://<host>/nosuchservice), 200 text/html (drops the host path, not comparable) <nil>, 0 launches

The CLI, same server:

$ GORP_API_KEY=<bogus> gorp launch list
level=ERROR msg="data failed to match schemas in oneOf(SaveAnalyticsSettings1401Response): json: cannot unmarshal object into Go value of type string"
exit code 1
$ gorp quality-gate check --launch-uuid 00000000-0000-0000-0000-000000000000
quality gate check error: 404 Not Found
exit code 10

What this means for users:

  1. A wrong or expired API key, the most common misconfiguration, gives a message that names neither 401 nor the token. gorp launch list prints the oneOf text (above). The spec declares 401 as oneOf(string, ErrorRS) for 282 of 358 operations, but the server answers with an OAuth body ({"error":"invalid_token","error_description":"…"}) that is neither.
  2. The generated client never shows the server's message. GenericOpenAPIError.Error() is the status line. The message is appended only for RFC 7807 fields (Title/Detail), which ReportPortal doesn't send. Model() is filled only for statuses the spec declares for that operation; 54 operations have a 404 branch and none of them is a launch operation.
  3. A non-JSON body on a declared status loses the status too: an HTML 403 from a proxy gives undefined response type.
  4. The Resty clients keep the body but as a raw multi-line dump, with no access to the error code other than parsing HTTPError.Response by hand.
  5. The Resty clients treat 200 text/html as success. With a host that points to the UI, GetLaunchesByFilterString returns err == nil and an empty page (last table row). Every Resty call goes through the same handler, so ReportingClient.StartLaunch would return an empty launch UUID the same way; that one was not tried live (it is a POST), only against a test server.
  6. There is no common way to ask "is this a 404?": *gorp.HTTPError on one client, *openapi.GenericOpenAPIError (no status code) on the other.

Expected

Every failed API call, through either client, returns one error type whose text has the HTTP status and the server's code and message (or the OAuth error and description, or the trimmed raw body), and which works with errors.As / errors.Is.

Response bodies to handle

Seen on the live server or in the service-api source:

  • {"errorCode":4041,"message":"…"}: ReportPortal ErrorRS, the code is a JSON number
  • {"error":"invalid_token","error_description":"…"}: rejected API key (pretty-printed, application/json;charset=ISO-8859-1)
  • {"timestamp":"…","status":404,"error":"Not Found","path":"…"}: Spring Boot default for an unknown path or method
  • empty body with WWW-Authenticate: Bearer error="invalid_token", error_description="…"
  • HTML or plain text from a proxy (403, 413, 502, …)
  • 200 text/html: the UI's index.html for a path outside /api

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions