Skip to content

Commit

Permalink
Merge pull request #118 from thorgate/fetch-content-type-text
Browse files Browse the repository at this point in the history
Use text as the default content type for fetch backend
  • Loading branch information
Jyrno42 authored Dec 3, 2021
2 parents 7b41bcb + 9b2b1cd commit 9cb468f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
if: github.event_name == 'pull_request' || (github.event_name == 'push' && github.ref == 'refs/heads/master')
strategy:
matrix:
node: [10, 12, 14]
node: [12, 14, 16]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ Using NPM
```sh
npm i tg-resources

# And resource backend
npm i @tg-resources/superagent

# Or
# And add fetch backend
npm i @tg-resources/fetch

# Or use superagent backend
npm i @tg-resources/superagent
```

Or using Yarn

```sh
yarn add tg-resources

# And resource backend
yarn add @tg-resources/superagent

# Or
# And fetch backend
yarn add @tg-resources/fetch

# Or use superagent backend
yarn add @tg-resources/superagent
```

### Does it work on react native?
Expand All @@ -52,7 +52,7 @@ import 'abortcontroller-polyfill/dist/polyfill-patch-fetch'

```js
import { Router } from "tg-resources"
import { SuperAgentResource: Resource } from "@tg-resources/superagent"
import { FetchResource: Resource } from "@tg-resources/fetch"

const onLoad = result => console.log(result);
const onError = result => console.error(result);
Expand Down
7 changes: 2 additions & 5 deletions packages/tg-resources-fetch/src/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,10 @@ function parseFetchResponse(
text: response.status === 204 ? null : '{}',
});
}
if (!response.headers.has('content-type')) {
// istanbul ignore next: Only happens w/ custom server that does not set Content-Type
throw new Error('Content type is missing from request');
}

// Get content string to use correct parser
const contentType: string = response.headers.get('content-type') as string;
const contentType: string = (response.headers.get('content-type') ||
'text/plain') as string;

if (contentType.includes('application/json')) {
return response.json().then((body: any) => ({
Expand Down

0 comments on commit 9cb468f

Please sign in to comment.