@@ -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