Created
March 15, 2018 04:17
-
-
Save kresnasatya/290ef29a6098990d519cff4b6eee8104 to your computer and use it in GitHub Desktop.
Contekkan pada saat fetch return response (json, text, whatever)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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