Skip to content

Instantly share code, notes, and snippets.

@kresnasatya
Created March 15, 2018 04:17
Show Gist options
  • Save kresnasatya/290ef29a6098990d519cff4b6eee8104 to your computer and use it in GitHub Desktop.
Save kresnasatya/290ef29a6098990d519cff4b6eee8104 to your computer and use it in GitHub Desktop.
Contekkan pada saat fetch return response (json, text, whatever)
let contentType = response.headers.get('content-type')
if (contentType.includes('application/json')) {
return response.json()
} else if (contentType.includes('text/html')) {
return response.text()
} else {
throw new Error(`Sorry, content-type ${contentType} not supported`)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment