diff --git a/src/templates/core/fetch/getResponseBody.hbs b/src/templates/core/fetch/getResponseBody.hbs index 1011380ee..1ee5303b8 100644 --- a/src/templates/core/fetch/getResponseBody.hbs +++ b/src/templates/core/fetch/getResponseBody.hbs @@ -3,8 +3,7 @@ export const getResponseBody = async (response: Response): Promise => { try { const contentType = response.headers.get('Content-Type'); if (contentType) { - const jsonTypes = ['application/json', 'application/problem+json'] - const isJSON = jsonTypes.some(type => contentType.toLowerCase().startsWith(type)); + const isJSON = /application\/([a-zA-Z0-9.]*\+)?json/.test(contentType.toLowerCase()); if (isJSON) { return await response.json(); } else { diff --git a/src/templates/core/node/getResponseBody.hbs b/src/templates/core/node/getResponseBody.hbs index 1011380ee..1ee5303b8 100644 --- a/src/templates/core/node/getResponseBody.hbs +++ b/src/templates/core/node/getResponseBody.hbs @@ -3,8 +3,7 @@ export const getResponseBody = async (response: Response): Promise => { try { const contentType = response.headers.get('Content-Type'); if (contentType) { - const jsonTypes = ['application/json', 'application/problem+json'] - const isJSON = jsonTypes.some(type => contentType.toLowerCase().startsWith(type)); + const isJSON = /application\/([a-zA-Z0-9.]*\+)?json/.test(contentType.toLowerCase()); if (isJSON) { return await response.json(); } else { diff --git a/src/templates/core/xhr/getResponseBody.hbs b/src/templates/core/xhr/getResponseBody.hbs index ccf83b1ff..8f1fbced0 100644 --- a/src/templates/core/xhr/getResponseBody.hbs +++ b/src/templates/core/xhr/getResponseBody.hbs @@ -3,8 +3,7 @@ export const getResponseBody = (xhr: XMLHttpRequest): any => { try { const contentType = xhr.getResponseHeader('Content-Type'); if (contentType) { - const jsonTypes = ['application/json', 'application/problem+json'] - const isJSON = jsonTypes.some(type => contentType.toLowerCase().startsWith(type)); + const isJSON = /application\/([a-zA-Z0-9.]*\+)?json/.test(contentType.toLowerCase()); if (isJSON) { return JSON.parse(xhr.responseText); } else { diff --git a/test/__snapshots__/index.spec.ts.snap b/test/__snapshots__/index.spec.ts.snap index e1c221495..d02a113a5 100644 --- a/test/__snapshots__/index.spec.ts.snap +++ b/test/__snapshots__/index.spec.ts.snap @@ -473,8 +473,7 @@ export const getResponseBody = async (response: Response): Promise => { try { const contentType = response.headers.get('Content-Type'); if (contentType) { - const jsonTypes = ['application/json', 'application/problem+json'] - const isJSON = jsonTypes.some(type => contentType.toLowerCase().startsWith(type)); + const isJSON = /application\\/([a-zA-Z0-9.]*\\+)?json/.test(contentType.toLowerCase()); if (isJSON) { return await response.json(); } else { @@ -3568,8 +3567,7 @@ export const getResponseBody = async (response: Response): Promise => { try { const contentType = response.headers.get('Content-Type'); if (contentType) { - const jsonTypes = ['application/json', 'application/problem+json'] - const isJSON = jsonTypes.some(type => contentType.toLowerCase().startsWith(type)); + const isJSON = /application\\/([a-zA-Z0-9.]*\\+)?json/.test(contentType.toLowerCase()); if (isJSON) { return await response.json(); } else {