Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch API の中で、catch メソッドを使ったエラーハンドリングがない #14

Closed
ghost opened this issue Sep 28, 2018 · 1 comment
Labels
enhancement New feature or request

Comments

@ghost
Copy link

ghost commented Sep 28, 2018

react_template や redux_template の中で、fetch メソッドが使われていますが、catch メソッドを使ったエラーハンドリングが必要だと思います。

現状の

fetch(CrudSampleRootUrl + 'SelectCount', {method, headers, body})
    .then(response => response.json())
    .then(data =>  {
        if(data.Message)
        {
            this.setState({ message : data.Message });
        }
        else if(data.ErrorMSG)
        {
            this.setState({ message : JSON.stringify(data.ErrorMSG) });
        }
        else if(data.ExceptionMSG)
        {
            this.setState({ message : JSON.stringify(data.ExceptionMSG) });
        }
    });

では、バックエンド・サーバーから、レスポンスとして何かしらのエラーメッセージが返された場合はそのメッセージが表示されますが、HTTP 404 エラーなど、バックエンド・サーバーに到達できなかった場合は、何もエラーメッセージが表示されません。

@daisukenishino2
Copy link
Member

daisukenishino2 commented Sep 28, 2018

@yusukemaegawa
以下を参考に修正しました。
JakeChampion/fetch#155 (comment)

@daisukenishino2 daisukenishino2 added the enhancement New feature or request label Sep 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant