Skip to content

Commit

Permalink
remove string check
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Nov 14, 2023
1 parent 0eab814 commit 9410b43
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions packages/core/src/internal/fetchSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,23 @@ async function* parseMultipartMixed(
}
}

async function* parseMaybeJSON(
response: Response
): AsyncIterableIterator<ExecutionResult> {
const text = await response.text();
try {
const result = JSON.parse(text);
if (process.env.NODE_ENV !== 'production') {
console.warn(
`Found response with content-type "text/plain" but it had a valid "application/json" response.`
);
}
yield result;
} catch (e) {
throw new Error(text);
}
}

async function* fetchOperation(
operation: Operation,
url: string,
Expand All @@ -172,25 +189,7 @@ async function* fetchOperation(
} else if (!/text\//i.test(contentType)) {
results = parseJSON(response);
} else {
if (contentType === 'text/plain') {
const text = await response.text();
if (text.startsWith('{')) {
try {
results = JSON.parse(text);
if (process.env.NODE_ENV !== 'production') {
console.warn(
`Found response with content-type "text/plain" but it had a valid "application/json" response.`
);
}
} catch (e) {
throw new Error(text);
}
} else {
throw new Error(text);
}
} else {
throw new Error(await response.text());
}
results = parseMaybeJSON(response);
}

let pending: ExecutionResult['pending'];
Expand Down

0 comments on commit 9410b43

Please sign in to comment.