Fetch API をラップした fetchWithErrorHandling を作る fetch APIを使うにあたって、ネットワークエラーなどのハンドリングを考えると少しエラーハンドリングの順序を工夫しないといけない。結論から言うと、以下のようなコードにすることで例えばChromeの ERR_CONNECTION_REFUSED も含めて拾うことができる。 const handleErrors = (res) => { if (res.ok) { return res; } switch (res.status) { case 400: throw Error('INVALID_TOKEN'); case 401: throw Error('UNAUTHORIZED'); case 500: throw Error('INTERNAL_SERVER_ERROR'); case 502: