Vue rookie asked axios how to catch request exception.

do you have any better suggestions for writing norms like this?

`
axios

                .post("/au/api/rulereleaseapply/findAllPubTask", {
                     branchCode: userInfor[0].branchCode,
                     userCode: userInfor[0].userCode,
                     busiinfoFive: "11"
                })
                .then(response => {
                    if (response.data.success) {
                      debugger;
                        console.log("=>", response.data);
                        _this.ruleReleaseVertifyData = response.data.entity.items;
                        loading.close();
                    } else {
                        loading.close();
                        this.$message({
                            showClose: true,
                            message: response.data.errorMessage,
                            type: "error"
                        });
                    }
                }).catch(response =>{
                  console.log("err",response);
                   loading.close();
                   loading.close();
                        this.$message({
                            showClose: true,
                            message: response.message,
                            type: "error"
                        });
                })

`

Mar.02,2021

specification, but it can be implemented with interceptors axios.interceptors.request and axios.interceptors.response , otherwise it's really tiring.

it's better to post a code instead of a sticker

when asking a question. There is a syntax error in

then. If an exception is thrown, it will also go to the catch () callback, which is not necessarily a network error.

Menu