cignium-hypermedia-client
Advanced tools
Comparing version 1.16.2 to 1.16.3
@@ -57,3 +57,3 @@ { | ||
}, | ||
"version": "1.16.2" | ||
"version": "1.16.3" | ||
} |
@@ -14,23 +14,30 @@ const mediaType = 'application/vnd.cignium.resource+json' | ||
if (response.status == 200) { | ||
if (contentType.startsWith(mediaType)) { | ||
return await response.json() | ||
} | ||
if (response.status == 401 && contentType && contentType.startsWith('text/html')) { | ||
location.href = method.toLowerCase() == 'get' ? response.url : location.href | ||
return | ||
} | ||
if (config && config.onRedirect) { | ||
let content = await response.text() | ||
content = config.onRedirect(response.url, content) | ||
if (content) { | ||
content.type = 'html' | ||
content.links = [{ rel: 'self', href: response.url }] | ||
} | ||
return content | ||
if (response.status >= 400 && response.status < 600) { | ||
throw Error(`${response.status}: ${response.statusText}`) | ||
} | ||
if (contentType.startsWith(mediaType)) { | ||
return await response.json() | ||
} | ||
if (config && config.onRedirect) { | ||
let content = await response.text() | ||
content = config.onRedirect(response.url, content) | ||
if (content) { | ||
content.type = 'html' | ||
content.links = [{ rel: 'self', href: response.url }] | ||
} | ||
location.href = response.url | ||
return null | ||
return content | ||
} | ||
throw Error(`${response.status}: ${response.statusText}`) | ||
location.href = response.url | ||
return null | ||
} |
Sorry, the diff of this file is too big to display
642985
3410