Skip to content

Commit

Permalink
catch aborted request errors (#889)
Browse files Browse the repository at this point in the history
* catch aborted request errors

* update changelog
  • Loading branch information
David Leger authored Jan 30, 2020
1 parent 1daeaf6 commit fccdd2b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 15 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
### Added

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

### Fixed

- Properly handle errors from aborted network requests in `manifold-plan-cost`.

## [0.9.3] - 2019-01-13

### Added
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@manifoldco/ui",
"description": "Manifold UI",
"version": "0.9.3",
"version": "0.9.4-rc.0",
"repository": {
"type": "git",
"url": "git+https://github.com/manifoldco/ui.git"
Expand Down
43 changes: 30 additions & 13 deletions src/components/manifold-plan-cost/manifold-plan-cost.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class ManifoldPlanCost {
@Prop() selectedFeatures?: Gateway.FeatureMap;
@State() calculatedCost?: number;
@State() controller?: AbortController;
@State() error?: string;
@Watch('plan') planChange() {
this.fetchCustomCost();
}
Expand All @@ -45,6 +46,7 @@ export class ManifoldPlanCost {

// Hide display while calculating
this.calculatedCost = undefined;
this.error = undefined;
if (this.controller) {
this.controller.abort();
} // If a request is in flight, cancel it
Expand All @@ -58,27 +60,42 @@ export class ManifoldPlanCost {
planID: this.plan.id,
features,
init: { signal: this.controller.signal },
}).then(({ cost }: Gateway.Price) => {
this.calculatedCost = cost || 0;
this.controller = undefined; // Request finished, so signal no longer needed
});
})
.then(({ cost }: Gateway.Price) => {
this.calculatedCost = cost || 0;
this.controller = undefined; // Request finished, so signal no longer needed
})
.catch(e => {
if (e.name !== 'AbortError') {
this.error = 'Error getting plan cost.';
}
});
}

@logger()
render() {
if (this.error) {
return <manifold-toast alertType="error">{this.error}</manifold-toast>;
}

if (this.calculatedCost === undefined) {
return <em>Calculating cost...</em>;
}

const meteredFeatures =
(this.plan && this.plan.meteredFeatures && this.plan.meteredFeatures.edges) || undefined;
const isConfigurable =
(this.plan &&
this.plan.configurableFeatures &&
this.plan.configurableFeatures.edges.length > 0) ||
false;

return (
<manifold-cost-display
baseCost={this.calculatedCost}
compact={this.compact}
meteredFeatures={
(this.plan && this.plan.meteredFeatures && this.plan.meteredFeatures.edges) || undefined
}
configurable={
(this.plan &&
this.plan.configurableFeatures &&
this.plan.configurableFeatures.edges.length > 0) ||
false
}
meteredFeatures={meteredFeatures}
configurable={isConfigurable}
/>
);
}
Expand Down

1 comment on commit fccdd2b

@vercel
Copy link

@vercel vercel bot commented on fccdd2b Jan 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.