Methods
(async) httpGetJson(url) → {Promise}
- Description:
httpGetJson
以內建fetch(node>=18與現代瀏覽器皆內建)執行GET, 並比照axios.get之回應與錯誤語意:
- 2xx: resolve {data}, data為回應內容(JSON可解析則為物件, 否則保留原字串)
- 非2xx: reject Error('Request failed with status code {status}')
- 網路層錯誤(連線失敗/DNS/中斷): fetch自身reject向外傳遞
注意與axios之已知差異: node端fetch不讀取HTTP_PROXY/HTTPS_PROXY環境變數(axios會), 需經proxy連線SSO之部署環境不適用本函數
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
url |
String | 輸入請求網址字串 |
Returns:
回傳Promise, resolve回{data}, reject回錯誤訊息
- Type
- Promise