Skip to content

Commit

Permalink
fix rate limit error check
Browse files Browse the repository at this point in the history
Fixes #3

Co-authored-by: amp127 <[email protected]>
  • Loading branch information
ianmacartney and amp127 committed Nov 12, 2024
1 parent 0bed05b commit 86b07e0
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 6 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Run tests
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
cache-dependency-path: |
example/package.json
package.json
node-version: "18.x"
cache: "npm"
- run: npm i
- run: npm ci
- run: cd example && npm i && cd ..
- run: npm test
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
"build:cjs": "tsc --project ./commonjs.json && echo '{\\n \"type\": \"commonjs\"\\n}' > dist/commonjs/package.json",
"dev": "cd example; npm run dev",
"typecheck": "tsc --noEmit",
"prepare": "npm run build"
"prepare": "npm run build",
"test": "vitest",
"test:debug": "vitest --inspect-brk --no-file-parallelism",
"test:coverage": "vitest run --coverage --coverage.reporter=text"
},
"files": [
"dist",
Expand Down
15 changes: 15 additions & 0 deletions src/client/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { expect, test } from "vitest";
import { ConvexError } from "convex/values";
import { isRateLimitError, RateLimitError } from "./index.js";
test("isRateLimitError", () => {
expect(
isRateLimitError(
new ConvexError({
kind: "RateLimited",
name: "foo",
retryAfter: 1,
} as RateLimitError)
)
).toBe(true);
expect(isRateLimitError(new ConvexError({ kind: "foo" }))).toBe(false);
});
6 changes: 1 addition & 5 deletions src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ export const HOUR = 60 * MINUTE;
export function isRateLimitError(
error: unknown
): error is { data: RateLimitError } {
return (
error instanceof ConvexError &&
"kind" in error.data &&
error.data.kind === "RateLimited"
);
return error instanceof ConvexError && error.data["kind"] === "RateLimited";
}

/**
Expand Down

0 comments on commit 86b07e0

Please sign in to comment.