Skip to content

Commit fccdd2b

Browse files
author
David Leger
authored
catch aborted request errors (#889)
* catch aborted request errors * update changelog
1 parent 1daeaf6 commit fccdd2b

File tree

3 files changed

+37
-15
lines changed

3 files changed

+37
-15
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,14 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
1010
### Added
1111

1212
- Added costs for configurable string feature options in `manifold-plan-selector`.
13-
- Added `read-only` attribute to `manifold-plan-details` to optionally disable inputs for configurable features.
13+
- Added `read-only` attribute to `manifold-plan-details` to optionally disable inputs for
14+
configurable features.
1415
- Added the ability to create and resize plans with configurable features.
1516

17+
### Fixed
18+
19+
- Properly handle errors from aborted network requests in `manifold-plan-cost`.
20+
1621
## [0.9.3] - 2019-01-13
1722

1823
### Added

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@manifoldco/ui",
33
"description": "Manifold UI",
4-
"version": "0.9.3",
4+
"version": "0.9.4-rc.0",
55
"repository": {
66
"type": "git",
77
"url": "git+https://github.com/manifoldco/ui.git"

src/components/manifold-plan-cost/manifold-plan-cost.tsx

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export class ManifoldPlanCost {
2020
@Prop() selectedFeatures?: Gateway.FeatureMap;
2121
@State() calculatedCost?: number;
2222
@State() controller?: AbortController;
23+
@State() error?: string;
2324
@Watch('plan') planChange() {
2425
this.fetchCustomCost();
2526
}
@@ -45,6 +46,7 @@ export class ManifoldPlanCost {
4546

4647
// Hide display while calculating
4748
this.calculatedCost = undefined;
49+
this.error = undefined;
4850
if (this.controller) {
4951
this.controller.abort();
5052
} // If a request is in flight, cancel it
@@ -58,27 +60,42 @@ export class ManifoldPlanCost {
5860
planID: this.plan.id,
5961
features,
6062
init: { signal: this.controller.signal },
61-
}).then(({ cost }: Gateway.Price) => {
62-
this.calculatedCost = cost || 0;
63-
this.controller = undefined; // Request finished, so signal no longer needed
64-
});
63+
})
64+
.then(({ cost }: Gateway.Price) => {
65+
this.calculatedCost = cost || 0;
66+
this.controller = undefined; // Request finished, so signal no longer needed
67+
})
68+
.catch(e => {
69+
if (e.name !== 'AbortError') {
70+
this.error = 'Error getting plan cost.';
71+
}
72+
});
6573
}
6674

6775
@logger()
6876
render() {
77+
if (this.error) {
78+
return <manifold-toast alertType="error">{this.error}</manifold-toast>;
79+
}
80+
81+
if (this.calculatedCost === undefined) {
82+
return <em>Calculating cost...</em>;
83+
}
84+
85+
const meteredFeatures =
86+
(this.plan && this.plan.meteredFeatures && this.plan.meteredFeatures.edges) || undefined;
87+
const isConfigurable =
88+
(this.plan &&
89+
this.plan.configurableFeatures &&
90+
this.plan.configurableFeatures.edges.length > 0) ||
91+
false;
92+
6993
return (
7094
<manifold-cost-display
7195
baseCost={this.calculatedCost}
7296
compact={this.compact}
73-
meteredFeatures={
74-
(this.plan && this.plan.meteredFeatures && this.plan.meteredFeatures.edges) || undefined
75-
}
76-
configurable={
77-
(this.plan &&
78-
this.plan.configurableFeatures &&
79-
this.plan.configurableFeatures.edges.length > 0) ||
80-
false
81-
}
97+
meteredFeatures={meteredFeatures}
98+
configurable={isConfigurable}
8299
/>
83100
);
84101
}

0 commit comments

Comments
 (0)