Skip to content

mw: send every API call through one request path #45

Closed

Description

@CameronBrooks11

Every call in internal/mw repeats the same steps: build the request, close the body, check the HTTP status, decode, check the error envelope. That's 8 copies across client.go and list.go, and they have drifted:

  • token, Login and Edit don't check the HTTP status, so a wiki that answers 503 with an HTML page gives a JSON parse error instead of the status. Against an httptest server returning 503 and <html>…:

    Login:        invalid character '<' looking for beginning of value
    Edit:         invalid character '<' looking for beginning of value
    FetchPage:    mediawiki api: 503 Service Unavailable
    RevisionText: mediawiki api: 503 Service Unavailable
    
  • Edit declares its own copy of apiError's shape and formats it differently (edit error code: info vs mediawiki api error code: info).

  • fetchBatchOnce redeclares the page/revision structs that apiResponse already has.

Fix: one helper that does a GET or POST, checks the status, and decodes into the caller's struct while handling the error envelope, with every call using it. Add a test that a non-200 from Login and Edit reports the status.

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