druxt-router 0.24.2 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # druxt-router
2
2
 
3
+ ## 0.25.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 7b749bd: Added improved error handling.
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [7b749bd]
12
+ - druxt@0.16.0
13
+
3
14
  ## 0.24.2
4
15
 
5
16
  ### Patch Changes
@@ -104,7 +104,7 @@ class DruxtRouter {
104
104
  }
105
105
  async getRoute(path) {
106
106
  const url = `/router/translate-path?path=${path}`;
107
- const response = await this.druxt.axios.get(url, {
107
+ const response = await this.druxt.get(url, {
108
108
  validateStatus: (status) => status < 500
109
109
  });
110
110
  const data = {
@@ -147,9 +147,16 @@ class DruxtRouter {
147
147
  break;
148
148
  }
149
149
  if (!(response.status >= 200 && response.status < 300)) {
150
- const error = new Error();
151
- error.response = response;
152
- throw error;
150
+ if (response.status === 404) {
151
+ if (typeof response.data !== "object") {
152
+ response.data = { errors: [{
153
+ detail: "Please ensure the Decoupled Router module is installed and configured correctly."
154
+ }] };
155
+ } else if (response.data.message || response.data.details) {
156
+ response.data.errors = [{ detail: [response.data.message, response.data.details].filter((s) => s).join("\n") }];
157
+ }
158
+ }
159
+ this.druxt.error({ response }, { url });
153
160
  }
154
161
  return route;
155
162
  }
@@ -112,7 +112,7 @@ class DruxtRouter {
112
112
  }
113
113
  async getRoute(path) {
114
114
  const url = `/router/translate-path?path=${path}`;
115
- const response = await this.druxt.axios.get(url, {
115
+ const response = await this.druxt.get(url, {
116
116
  validateStatus: (status) => status < 500
117
117
  });
118
118
  const data = {
@@ -155,9 +155,16 @@ class DruxtRouter {
155
155
  break;
156
156
  }
157
157
  if (!(response.status >= 200 && response.status < 300)) {
158
- const error = new Error();
159
- error.response = response;
160
- throw error;
158
+ if (response.status === 404) {
159
+ if (typeof response.data !== "object") {
160
+ response.data = { errors: [{
161
+ detail: "Please ensure the Decoupled Router module is installed and configured correctly."
162
+ }] };
163
+ } else if (response.data.message || response.data.details) {
164
+ response.data.errors = [{ detail: [response.data.message, response.data.details].filter((s) => s).join("\n") }];
165
+ }
166
+ }
167
+ this.druxt.error({ response }, { url });
161
168
  }
162
169
  return route;
163
170
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "druxt-router",
3
- "version": "0.24.2",
3
+ "version": "0.25.0",
4
4
  "description": "Drupal router for Nuxt, powered by the Drupal Decoupled Router module.",
5
5
  "keywords": [
6
6
  "cms",
@@ -42,7 +42,7 @@
42
42
  "templates"
43
43
  ],
44
44
  "dependencies": {
45
- "druxt": "^0.15.0",
45
+ "druxt": "^0.16.0",
46
46
  "url-parse": "^1.4.7"
47
47
  },
48
48
  "optionalDependencies": {