Mirror: The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

chore(core): try to parse a text/plain content-type response as json (#3430)

authored by

Jovi De Croock and committed by
GitHub
94e0c310 f2c59c56

+23 -1
+5
.changeset/silver-planets-sniff.md
··· 1 + --- 2 + '@urql/core': minor 3 + --- 4 + 5 + Try to parse `text/plain` content-type as JSON before bailing out with an error.
+18 -1
packages/core/src/internal/fetchSource.ts
··· 147 147 } 148 148 } 149 149 150 + async function* parseMaybeJSON( 151 + response: Response 152 + ): AsyncIterableIterator<ExecutionResult> { 153 + const text = await response.text(); 154 + try { 155 + const result = JSON.parse(text); 156 + if (process.env.NODE_ENV !== 'production') { 157 + console.warn( 158 + `Found response with content-type "text/plain" but it had a valid "application/json" response.` 159 + ); 160 + } 161 + yield result; 162 + } catch (e) { 163 + throw new Error(text); 164 + } 165 + } 166 + 150 167 async function* fetchOperation( 151 168 operation: Operation, 152 169 url: string, ··· 172 189 } else if (!/text\//i.test(contentType)) { 173 190 results = parseJSON(response); 174 191 } else { 175 - throw new Error(await response.text()); 192 + results = parseMaybeJSON(response); 176 193 } 177 194 178 195 let pending: ExecutionResult['pending'];