glib-web 2.6.5 → 2.6.6

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/action.js CHANGED
@@ -132,9 +132,9 @@ export default class Action {
132
132
  const name = spec.action;
133
133
  if (TypeUtils.isString(name)) {
134
134
  if (name.startsWith("component/")) {
135
- this.executeLocal(name, spec, component);
135
+ return this.executeLocal(name, spec, component);
136
136
  } else {
137
- this.executeGlobal(name, spec, component, params);
137
+ return this.executeGlobal(name, spec, component, params);
138
138
  }
139
139
  } else {
140
140
  console.warn(`Invalid action: "${name}"`);
@@ -151,7 +151,7 @@ export default class Action {
151
151
  }
152
152
 
153
153
  static executeGlobal(name, spec, component, params) {
154
- this._executeInternal(name, spec, component, params, actions);
154
+ return this._executeInternal(name, spec, component, params, actions);
155
155
  }
156
156
 
157
157
  static _executeInternal(name, spec, component, params, registry) {
@@ -163,13 +163,10 @@ export default class Action {
163
163
  if (!logDisabled) {
164
164
  console.debug(`Executing "${actionName}"`);
165
165
  }
166
- action.execute(spec, component, params);
166
+ return action.execute(spec, component, params);
167
167
  } catch (e) {
168
- GLib.settings.errorHandler(
169
- new Error(
170
- `Failed executing command "${actionName}". Error: ${e.message}`
171
- )
172
- );
168
+ GLib.settings.errorHandler(e);
169
+ return null;
173
170
  }
174
171
  }
175
172
 
@@ -195,7 +192,7 @@ export default class Action {
195
192
  }
196
193
 
197
194
  static executeCustom(name, spec, component, params) {
198
- this._executeInternal(name, spec, component, params, customActions);
195
+ return this._executeInternal(name, spec, component, params, customActions);
199
196
  }
200
197
  }
201
198
 
@@ -1,19 +1,34 @@
1
1
  export default class {
2
- execute(properties, controller) {
2
+ execute(spec, component) {
3
+ return new Promise(resolve => {
4
+ GLib.http.execute(
5
+ spec,
6
+ "GET",
7
+ component,
8
+ (page, response) => {
9
+ this.handleSuccess(page, spec, component);
10
+ resolve({ page: page, response: response });
11
+ },
12
+ (error, response) => {
13
+ resolve({ error: error, response: response });
14
+ }
15
+ );
16
+ });
17
+ }
18
+
19
+ handleSuccess(page, spec, component) {
3
20
  const currentUrl = window.location.href;
4
21
 
5
- GLib.http.execute(properties, "GET", controller, (page, response) => {
6
- Utils.type.ifString(properties.historyUrl, historyUrl => {
7
- const cleanUrl = Utils.url.htmlUrl(historyUrl);
8
- if (cleanUrl !== currentUrl) {
9
- const data = Object.assign({}, window.vueApp.page, {
10
- replayGetResponse: page.onResponse
11
- });
22
+ Utils.type.ifString(spec.historyUrl, historyUrl => {
23
+ const cleanUrl = Utils.url.htmlUrl(historyUrl);
24
+ if (cleanUrl !== currentUrl) {
25
+ const data = Object.assign({}, window.vueApp.page, {
26
+ replayGetResponse: page.onResponse
27
+ });
12
28
 
13
- Utils.history.pushPage(data, cleanUrl);
14
- }
15
- });
16
- GLib.action.handleResponse(page, controller);
29
+ Utils.history.pushPage(data, cleanUrl);
30
+ }
17
31
  });
32
+ GLib.action.handleResponse(page, component);
18
33
  }
19
34
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "glib-web",
3
- "version": "2.6.5",
3
+ "version": "2.6.6",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/utils/http.js CHANGED
@@ -149,7 +149,7 @@ export default class {
149
149
  });
150
150
  }
151
151
 
152
- static execute(properties, methodName, component, jsonHandler) {
152
+ static execute(properties, methodName, component, jsonHandler, errorHandler) {
153
153
  this.startIndicator(component);
154
154
 
155
155
  // `fetch()` only supports uppercase
@@ -185,12 +185,12 @@ export default class {
185
185
  .then(res => {
186
186
  vm.stopIndicator(component);
187
187
 
188
+ response = res;
188
189
  if (res.status >= 500) {
189
190
  throw "Server error";
190
191
  } else if (res.status >= 400) {
191
192
  throw "Not accessible";
192
193
  } else {
193
- response = res;
194
194
  return res.json();
195
195
  }
196
196
  })
@@ -200,9 +200,17 @@ export default class {
200
200
  })
201
201
  .catch(error => {
202
202
  vm.stopIndicator(component);
203
+
203
204
  if (!request.canceled) {
204
- console.error("Error:", error);
205
- Utils.launch.snackbar.error(error, component);
205
+ const message = error.toString();
206
+
207
+ console.error("Error:", message);
208
+
209
+ if (errorHandler) {
210
+ errorHandler(error, response);
211
+ } else {
212
+ Utils.launch.snackbar.error(message, component);
213
+ }
206
214
  } else {
207
215
  console.info("Canceled");
208
216
  }