You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by mi...@apache.org on 2018/10/23 02:11:16 UTC
[incubator-dubbo-ops] branch develop updated: Optimize error
unified processing (#157)
This is an automated email from the ASF dual-hosted git repository.
min pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/incubator-dubbo-ops.git
The following commit(s) were added to refs/heads/develop by this push:
new b53b548 Optimize error unified processing (#157)
b53b548 is described below
commit b53b54874ecb9ec2ed9eb756bfb7658938c8e1c1
Author: Zhiguo.Chen <ch...@live.com>
AuthorDate: Tue Oct 23 10:11:12 2018 +0800
Optimize error unified processing (#157)
---
README.md | 2 +-
.../apache/dubbo/admin/common/CommonResponse.java | 30 +++++++---------------
dubbo-admin-frontend/src/components/http-common.js | 18 ++++++++++++-
3 files changed, 27 insertions(+), 23 deletions(-)
diff --git a/README.md b/README.md
index 0d95fa4..1b08e2e 100644
--- a/README.md
+++ b/README.md
@@ -21,7 +21,7 @@
> The generic configuration, it's permanent.
> - `application-develop.properties`
> The configuration for develop, it will be work when you use Maven's `develop` Profile.
-> - `application-production.properties` (default)
+> - `application-production.properties` (default)
> The configuration for production, it will be work when you use Maven's `production` Profile. Meanwhile, it's maven's default profile in this project.
### Build setup
diff --git a/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/common/CommonResponse.java b/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/common/CommonResponse.java
index b1f5f11..20ee8d5 100644
--- a/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/common/CommonResponse.java
+++ b/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/common/CommonResponse.java
@@ -16,9 +16,6 @@
*/
package org.apache.dubbo.admin.common;
-import com.google.common.collect.Lists;
-
-import java.util.Collection;
import java.util.HashMap;
/**
@@ -32,6 +29,10 @@ public class CommonResponse extends HashMap<String, Object> {
private static final String DATA = "data";
+ private static final String REDIRECT = "redirect";
+
+ private static final String EMPTY = "";
+
public boolean isSuccess() {
return get(SUCCESS) != null && (Boolean) get(SUCCESS);
}
@@ -40,7 +41,7 @@ public class CommonResponse extends HashMap<String, Object> {
if (get(MESSAGE) != null) {
return (String) get(MESSAGE);
}
- return "";
+ return EMPTY;
}
private CommonResponse() {
@@ -66,32 +67,19 @@ public class CommonResponse extends HashMap<String, Object> {
}
public CommonResponse redirect(String url) {
- this.put("redirect", url);
+ this.put(REDIRECT, url);
return this;
}
public CommonResponse setData(Object data) {
- Collection collection;
- if (!containsKey(DATA) || get(DATA) == null) {
- collection = Lists.newArrayList();
- put(DATA, collection);
- } else {
- collection = (Collection) get(DATA);
- }
- collection.add(data);
- return this;
+ return putData(DATA, data);
}
- public CommonResponse setData(String key, Object data) {
+ public CommonResponse putData(String key, Object data) {
this.put(key, data);
return this;
}
- public CommonResponse setData(Collection collection) {
- this.put(DATA, collection);
- return this;
- }
-
public static CommonResponse createCommonResponse() {
CommonResponse commonResponse = new CommonResponse();
commonResponse.success();
@@ -104,4 +92,4 @@ public class CommonResponse extends HashMap<String, Object> {
commonResponse.setData(data);
return commonResponse;
}
-}
\ No newline at end of file
+}
diff --git a/dubbo-admin-frontend/src/components/http-common.js b/dubbo-admin-frontend/src/components/http-common.js
index 5c44c9a..6516020 100644
--- a/dubbo-admin-frontend/src/components/http-common.js
+++ b/dubbo-admin-frontend/src/components/http-common.js
@@ -15,7 +15,23 @@
* limitations under the License.
*/
import axios from 'axios'
+import Vue from 'vue'
+import HttpStatus from 'http-status'
-export const AXIOS = axios.create({
+let instance = axios.create({
baseURL: 'http://localhost:8080/api/dev'
})
+
+instance.interceptors.response.use((response) => {
+ return response
+}, (error) => {
+ if (error.message.indexOf('Network Error') >= 0) {
+ Vue.prototype.$notify.error('Network error, please check your network settings!')
+ } else if (error.response.status === HttpStatus.UNAUTHORIZED) {
+ // TODO jump to url
+ } else if (error.response.status >= HttpStatus.BAD_REQUEST) {
+ Vue.prototype.$notify.error(error.response.data.message)
+ }
+})
+
+export const AXIOS = instance