Browse Source

update:评论失败返回data&增加更新失败的回调

adam 4 years ago
parent
commit
4cb43d058f
8 changed files with 41 additions and 29 deletions
  1. 10
    4
      lib/App.js
  2. 1
    1
      lib/App.js.map
  3. 4
    4
      lib/index.js
  4. 1
    1
      lib/index.js.map
  5. 5
    5
      lib/version.json
  6. 1
    1
      package.json
  7. 15
    9
      src/App.js
  8. 4
    4
      src/index.js

+ 10
- 4
lib/App.js View File

433
         _this6.setState({ list: list, total: total + 1 });
433
         _this6.setState({ list: list, total: total + 1 });
434
         _this6.props.onCountChange(total + 1);
434
         _this6.props.onCountChange(total + 1);
435
       }).catch(function (error) {
435
       }).catch(function (error) {
436
-        _this6.props.onCommentFail(error.response.status);
436
+        _this6.props.onCommentFail(error.response.status, error.response.data);
437
         _this6.errorHandler(error);
437
         _this6.errorHandler(error);
438
       }).finally(function () {
438
       }).finally(function () {
439
         _this6.handleChangeLoading("sCreateComment", false);
439
         _this6.handleChangeLoading("sCreateComment", false);
508
         });
508
         });
509
         _this8.props.onUpdateComment("comment");
509
         _this8.props.onUpdateComment("comment");
510
         _this8.setState({ list: list });
510
         _this8.setState({ list: list });
511
-      }).catch(this.errorHandler).finally(function () {
511
+      }).catch(function (error) {
512
+        _this8.props.onCommentFail(error.response.status, error.response.data);
513
+        _this8.errorHandler(error);
514
+      }).finally(function () {
512
         _this8.handleChangeLoading("sUpdateComment", false);
515
         _this8.handleChangeLoading("sUpdateComment", false);
513
       });
516
       });
514
     }
517
     }
551
         });
554
         });
552
         _this9.setState({ list: list });
555
         _this9.setState({ list: list });
553
       }).catch(function (error) {
556
       }).catch(function (error) {
554
-        _this9.props.onCommentFail(error.response.status);
557
+        _this9.props.onCommentFail(error.response.status, error.response.data);
555
         _this9.errorHandler(error);
558
         _this9.errorHandler(error);
556
       }).finally(function () {
559
       }).finally(function () {
557
         _this9.handleChangeLoading("sCreateReply", false);
560
         _this9.handleChangeLoading("sCreateReply", false);
627
           _this11.sGetReply({ commentId: commentId, page: i });
630
           _this11.sGetReply({ commentId: commentId, page: i });
628
         }
631
         }
629
         _this11.props.onUpdateComment("reply");
632
         _this11.props.onUpdateComment("reply");
630
-      }).catch(this.errorHandler).finally(function () {
633
+      }).catch(function (error) {
634
+        _this11.props.onCommentFail(error.response.status, error.response.data);
635
+        _this11.errorHandler(error);
636
+      }).finally(function () {
631
         _this11.handleChangeLoading("sUpdateReply", false);
637
         _this11.handleChangeLoading("sUpdateReply", false);
632
       });
638
       });
633
     }
639
     }

+ 1
- 1
lib/App.js.map
File diff suppressed because it is too large
View File


+ 4
- 4
lib/index.js View File

125
     type: 3,
125
     type: 3,
126
     businessId: "5ea8320dedd68200018e733d",
126
     businessId: "5ea8320dedd68200018e733d",
127
     businessUserId: 4,
127
     businessUserId: 4,
128
-    userId: 58297,
128
+    userId: 45,
129
     currentUser: {
129
     currentUser: {
130
-      user_id: 58297
130
+      user_id: 45
131
     },
131
     },
132
     userAvaHoverData: {
132
     userAvaHoverData: {
133
       71763: {
133
       71763: {
181
     onDelete: function onDelete(type, data) {
181
     onDelete: function onDelete(type, data) {
182
       console.log(type, data);
182
       console.log(type, data);
183
     },
183
     },
184
-    onCommentFail: function onCommentFail(data) {
185
-      console.log("onCommentFail", data);
184
+    onCommentFail: function onCommentFail(status, data) {
185
+      console.log("onCommentFail", status, data);
186
     },
186
     },
187
     onUpdateComment: function onUpdateComment(type, data) {
187
     onUpdateComment: function onUpdateComment(type, data) {
188
       console.log("onUpdateComment", type);
188
       console.log("onUpdateComment", type);

+ 1
- 1
lib/index.js.map
File diff suppressed because it is too large
View File


+ 5
- 5
lib/version.json View File

1
 {
1
 {
2
     "name":       "comment",
2
     "name":       "comment",
3
-    "buildDate":  1604757339795,
4
-    "version":    "1.0.4",
5
-    "numCommits": 219,
6
-    "hash":       "1e52141",
7
-    "dirty":      false
3
+    "buildDate":  1604847384031,
4
+    "version":    "1.2.4",
5
+    "numCommits": 225,
6
+    "hash":       "1377102",
7
+    "dirty":      true
8
 }
8
 }

+ 1
- 1
package.json View File

1
 {
1
 {
2
   "name": "comment",
2
   "name": "comment",
3
-  "version": "1.2.3",
3
+  "version": "1.2.4",
4
   "main": "lib/App.js",
4
   "main": "lib/App.js",
5
   "description": "通用评论",
5
   "description": "通用评论",
6
   "keywords": [
6
   "keywords": [

+ 15
- 9
src/App.js View File

60
     this.axios = axios;
60
     this.axios = axios;
61
     this.axios.defaults.withCredentials = true;
61
     this.axios.defaults.withCredentials = true;
62
     if (this.props.token) {
62
     if (this.props.token) {
63
-      this.axios.defaults.headers.common[
64
-        "Authorization"
65
-      ] = `Bearer ${this.props.token}`;
63
+      this.axios.defaults.headers.common["Authorization"] = `Bearer ${
64
+        this.props.token
65
+      }`;
66
     }
66
     }
67
   }
67
   }
68
 
68
 
137
       action: content.replies
137
       action: content.replies
138
         ? "comment"
138
         ? "comment"
139
         : content.reply
139
         : content.reply
140
-        ? "replyToReply"
141
-        : "reply",
140
+          ? "replyToReply"
141
+          : "reply",
142
       replyId,
142
       replyId,
143
       commentId,
143
       commentId,
144
       userId,
144
       userId,
311
         this.props.onCountChange(total + 1);
311
         this.props.onCountChange(total + 1);
312
       })
312
       })
313
       .catch(error => {
313
       .catch(error => {
314
-        this.props.onCommentFail(error.response.status);
314
+        this.props.onCommentFail(error.response.status, error.response.data);
315
         this.errorHandler(error);
315
         this.errorHandler(error);
316
       })
316
       })
317
       .finally(() => {
317
       .finally(() => {
370
         this.props.onUpdateComment("comment");
370
         this.props.onUpdateComment("comment");
371
         this.setState({ list });
371
         this.setState({ list });
372
       })
372
       })
373
-      .catch(this.errorHandler)
373
+      .catch(error => {
374
+        this.props.onCommentFail(error.response.status, error.response.data);
375
+        this.errorHandler(error);
376
+      })
374
       .finally(() => {
377
       .finally(() => {
375
         this.handleChangeLoading("sUpdateComment", false);
378
         this.handleChangeLoading("sUpdateComment", false);
376
       });
379
       });
411
         this.setState({ list });
414
         this.setState({ list });
412
       })
415
       })
413
       .catch(error => {
416
       .catch(error => {
414
-        this.props.onCommentFail(error.response.status);
417
+        this.props.onCommentFail(error.response.status, error.response.data);
415
         this.errorHandler(error);
418
         this.errorHandler(error);
416
       })
419
       })
417
       .finally(() => {
420
       .finally(() => {
472
         }
475
         }
473
         this.props.onUpdateComment("reply");
476
         this.props.onUpdateComment("reply");
474
       })
477
       })
475
-      .catch(this.errorHandler)
478
+      .catch(error => {
479
+        this.props.onCommentFail(error.response.status, error.response.data);
480
+        this.errorHandler(error);
481
+      })
476
       .finally(() => {
482
       .finally(() => {
477
         this.handleChangeLoading("sUpdateReply", false);
483
         this.handleChangeLoading("sUpdateReply", false);
478
       });
484
       });

+ 4
- 4
src/index.js View File

90
     type: 3,
90
     type: 3,
91
     businessId: "5ea8320dedd68200018e733d",
91
     businessId: "5ea8320dedd68200018e733d",
92
     businessUserId: 4,
92
     businessUserId: 4,
93
-    userId: 58297,
93
+    userId: 45,
94
     currentUser: {
94
     currentUser: {
95
-      user_id: 58297
95
+      user_id: 45
96
     },
96
     },
97
     userAvaHoverData: {
97
     userAvaHoverData: {
98
       71763: {
98
       71763: {
146
     onDelete: (type, data) => {
146
     onDelete: (type, data) => {
147
       console.log(type, data);
147
       console.log(type, data);
148
     },
148
     },
149
-    onCommentFail: data => {
150
-      console.log("onCommentFail", data);
149
+    onCommentFail: (status, data) => {
150
+      console.log("onCommentFail", status, data);
151
     },
151
     },
152
     onUpdateComment: (type, data) => {
152
     onUpdateComment: (type, data) => {
153
       console.log("onUpdateComment", type);
153
       console.log("onUpdateComment", type);