Skip to content
This repository was archived by the owner on Oct 31, 2024. It is now read-only.

Commit 8958ab8

Browse files
committed
fix: Adds ejson header on all requests
1 parent f9edefc commit 8958ab8

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ archive/
1717
node_modules
1818

1919
# https://github.com/avajs/ava/blob/main/docs/recipes/code-coverage.md
20-
coverage
20+
coverage
21+
22+
tmp

src/client.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,8 @@ export class Collection<TSchema = Document> {
599599
} = this.connection;
600600

601601
const headers = new Headers(h);
602+
headers.set("content-type", "application/ejson");
603+
602604
if (requestOptions.operationName) {
603605
headers.set("x-realm-op-name", requestOptions.operationName);
604606
}
@@ -621,9 +623,14 @@ export class Collection<TSchema = Document> {
621623
if (response.status < 200 || response.status >= 400) {
622624
let errorText: string | undefined;
623625
try {
624-
errorText = ((await response.json()) as { error: string })?.error;
626+
errorText = ((await response.clone().json()) as { error: string })
627+
?.error;
625628
} catch {
626-
/* c8 ignore next */
629+
try {
630+
errorText = await response.clone().text();
631+
} catch {
632+
errorText = undefined;
633+
}
627634
}
628635

629636
const fallbackMessage = {

0 commit comments

Comments
 (0)