Skip to content

Commit

Permalink
fix: error handling in doFetch (#864)
Browse files Browse the repository at this point in the history
  • Loading branch information
anku255 committed Jun 19, 2024
1 parent fb3ffa7 commit 528ea98
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 12 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [unreleased]

## [18.0.1] - 2024-06-19

### Fixes

- Fix a bug that was preventing errors from being caught in the fetch function, thus bypassing our error handling.

## [18.0.0] - 2024-05-23

### Breaking change
Expand Down
6 changes: 3 additions & 3 deletions lib/build/utils.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/build/version.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/build/version.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions lib/ts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { LoginMethod, User } from "./user";
import { SessionContainer } from "./recipe/session";
import { ProcessState, PROCESS_STATE } from "./processState";

export const doFetch: typeof fetch = (input: RequestInfo | URL, init?: RequestInit | undefined) => {
export const doFetch: typeof fetch = async (input: RequestInfo | URL, init?: RequestInit | undefined) => {
// frameworks like nextJS cache fetch GET requests (https://nextjs.org/docs/app/building-your-application/caching#data-cache)
// we don't want that because it may lead to weird behaviour when querying the core.
if (init === undefined) {
Expand All @@ -27,7 +27,7 @@ export const doFetch: typeof fetch = (input: RequestInfo | URL, init?: RequestIn
}
const fetchFunction = typeof fetch !== "undefined" ? fetch : crossFetch;
try {
return fetchFunction(input, init);
return await fetchFunction(input, init);
} catch (e) {
// Cloudflare Workers don't support the 'cache' field in RequestInit.
// To work around this, we delete the 'cache' field and retry the fetch if the error is due to the missing 'cache' field.
Expand All @@ -43,7 +43,7 @@ export const doFetch: typeof fetch = (input: RequestInfo | URL, init?: RequestIn
const newOpts = { ...init };
delete newOpts.cache;

return fetchFunction(input, newOpts);
return await fetchFunction(input, newOpts);
}
};

Expand Down
2 changes: 1 addition & 1 deletion lib/ts/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
export const version = "18.0.0";
export const version = "18.0.1";

export const cdiSupported = ["5.0"];

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "supertokens-node",
"version": "18.0.0",
"version": "18.0.1",
"description": "NodeJS driver for SuperTokens core",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 528ea98

Please sign in to comment.