Skip to content

replace request with axios#128

Open
cstrahan wants to merge 10 commits into
masterfrom
cstrahan/typescript2
Open

replace request with axios#128
cstrahan wants to merge 10 commits into
masterfrom
cstrahan/typescript2

Conversation

@cstrahan
Copy link
Copy Markdown
Contributor

@cstrahan cstrahan commented Aug 5, 2025

We're going to have a lot of churn if we don't eventually get a consistent style/format enforced, so to minimize future merge conflicts (or, put another way, increase how quickly I can wrap up this PR and any future work), the bulk of this PR starts with commits to set up automatic formatting (using Google's style guides), increase type coverage, etc.

The last two commits (as of now):

  • initial tests: implement tests for the existing request implementation
  • request -> axios: replaces request with axios and amends the tests as required (e.g. updates the mocks)

@cstrahan
Copy link
Copy Markdown
Contributor Author

cstrahan commented Aug 5, 2025

I've iterated on running the backend test suite (CTS) with these changes, fixing bugs, rinse-repeat, and everything looks good to me now.

Some request-vs-axios differences that this process highlighted:

  • axios uses response.status, request uses response.statusCode, and
  • axios uses response.data instead of response.body.
    • I could monkey patch the response objects to include statusCode and body properties, but I'd rather just announce the breaking change.
  • axios will decompress responses automatically by default, whereas request will return the original, compressed response.
    • Solving this from our reverse dependencies is slightly more involved, so I'm more inclined to (for now) to keep this work backward compatible: to minimize breakage, I have set decompress: false wherever we make a request.
    • Ultimately, I'd like remove this setting and allow axios to decompress responses automatically, but we can handle that later.

I now just need to update the tests to reflect the new behavior.

@cstrahan
Copy link
Copy Markdown
Contributor Author

cstrahan commented Aug 6, 2025

Another notable difference:

We now use

export class CoronerClient { /* ... */ }

where we used to have

module.exports = CoronerClient;

So now when you require('backtrace-morgue/dist/lib/coroner.js'), that returns an object with a CoronerClient property, so you'd now access it like this (assuming JS and require):

// This:
const { CoronerClient } = require("backtrace-morgue/dist/lib/coroner.js");

// Or this:
// const CoronerClient = require("backtrace-morgue/dist/lib/coroner.js").CoronerClient;

// But NOT this old way:
// const CoronerClient = require("backtrace-morgue/dist/lib/coroner.js");
// ... trying to do `new CoronerClient()` will raise an exception stating that `CoronerClient` is not (of course) a constructor.

In light of the aforementioned implementation choices (and rationale given), I see this as a benefit: if someone blindly updates the version backtrace-morgue, they'll get an easily debugable exception, which should prompt them to go read the release notes where they'd learn (the much harder to debug) need to handle status vs statusCode, etc.

@cstrahan
Copy link
Copy Markdown
Contributor Author

cstrahan commented Aug 6, 2025

If we want to do a non-alpha release, we should bump the major version, for the sake of anyone using backtrace-morgue as a library.

@cstrahan cstrahan force-pushed the cstrahan/typescript2 branch from fe8b670 to 5a8cbfd Compare August 6, 2025 16:32
@cstrahan
Copy link
Copy Markdown
Contributor Author

cstrahan commented Aug 6, 2025

Confirmed this morning that all CTS tests pass.

Performed an interactive rebase to clean up the commit history.

@cstrahan cstrahan force-pushed the cstrahan/typescript2 branch from 5a8cbfd to 70aedad Compare August 11, 2025 19:47
@cstrahan
Copy link
Copy Markdown
Contributor Author

I just published 2.0.0-alpha.0 with these changes.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant