Skip to content

Commit 7c726a0

Browse files
committed
fix isJSON checks for custom json types
1 parent beec04a commit 7c726a0

File tree

4 files changed

+5
-10
lines changed

4 files changed

+5
-10
lines changed

src/templates/core/fetch/getResponseBody.hbs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ export const getResponseBody = async (response: Response): Promise<any> => {
33
try {
44
const contentType = response.headers.get('Content-Type');
55
if (contentType) {
6-
const jsonTypes = ['application/json', 'application/problem+json']
7-
const isJSON = jsonTypes.some(type => contentType.toLowerCase().startsWith(type));
6+
const isJSON = /application\\/([a-zA-Z0-9.]*\\+)?json/.test(contentType.toLowerCase());
87
if (isJSON) {
98
return await response.json();
109
} else {

src/templates/core/node/getResponseBody.hbs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ export const getResponseBody = async (response: Response): Promise<any> => {
33
try {
44
const contentType = response.headers.get('Content-Type');
55
if (contentType) {
6-
const jsonTypes = ['application/json', 'application/problem+json']
7-
const isJSON = jsonTypes.some(type => contentType.toLowerCase().startsWith(type));
6+
const isJSON = /application\\/([a-zA-Z0-9.]*\\+)?json/.test(contentType.toLowerCase());
87
if (isJSON) {
98
return await response.json();
109
} else {

src/templates/core/xhr/getResponseBody.hbs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ export const getResponseBody = (xhr: XMLHttpRequest): any => {
33
try {
44
const contentType = xhr.getResponseHeader('Content-Type');
55
if (contentType) {
6-
const jsonTypes = ['application/json', 'application/problem+json']
7-
const isJSON = jsonTypes.some(type => contentType.toLowerCase().startsWith(type));
6+
const isJSON = /application\\/([a-zA-Z0-9.]*\\+)?json/.test(contentType.toLowerCase());
87
if (isJSON) {
98
return JSON.parse(xhr.responseText);
109
} else {

test/__snapshots__/index.spec.ts.snap

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -473,8 +473,7 @@ export const getResponseBody = async (response: Response): Promise<any> => {
473473
try {
474474
const contentType = response.headers.get('Content-Type');
475475
if (contentType) {
476-
const jsonTypes = ['application/json', 'application/problem+json']
477-
const isJSON = jsonTypes.some(type => contentType.toLowerCase().startsWith(type));
476+
const isJSON = /application\\/([a-zA-Z0-9.]*\\+)?json/.test(contentType.toLowerCase());
478477
if (isJSON) {
479478
return await response.json();
480479
} else {
@@ -3568,8 +3567,7 @@ export const getResponseBody = async (response: Response): Promise<any> => {
35683567
try {
35693568
const contentType = response.headers.get('Content-Type');
35703569
if (contentType) {
3571-
const jsonTypes = ['application/json', 'application/problem+json']
3572-
const isJSON = jsonTypes.some(type => contentType.toLowerCase().startsWith(type));
3570+
const isJSON = /application\\/([a-zA-Z0-9.]*\\+)?json/.test(contentType.toLowerCase());
35733571
if (isJSON) {
35743572
return await response.json();
35753573
} else {

0 commit comments

Comments
 (0)