33import {
44 RoutingConfig ,
55 $RoutingConfig ,
6- routingConfigurationApiClient ,
76 TemplateDto ,
87 RoutingConfigStatusActive ,
98} from 'nhs-notify-backend-client' ;
@@ -12,6 +11,7 @@ import { getSessionServer } from './amplify-utils';
1211import { logger } from 'nhs-notify-web-template-management-utils/logger' ;
1312import { getTemplate } from './form-actions' ;
1413import { sortAscByUpdatedAt } from './sort' ;
14+ import { routingConfigurationApiClient } from 'nhs-notify-backend-client/src/routing-config-api-client' ;
1515
1616export async function getRoutingConfigs ( ) : Promise < RoutingConfig [ ] > {
1717 const { accessToken } = await getSessionServer ( ) ;
@@ -55,9 +55,7 @@ export async function countRoutingConfigs(
5555 ) ;
5656
5757 if ( error ) {
58- logger . error ( `Failed to count routing configuration for ${ status } ` , {
59- error,
60- } ) ;
58+ logger . error ( `Failed to count routing configuration for ${ status } ` , error ) ;
6159 return 0 ;
6260 }
6361
@@ -79,19 +77,15 @@ export async function getRoutingConfig(
7977 ) ;
8078
8179 if ( error ) {
82- logger . error ( 'Failed to get routing configuration' , {
83- error : error ,
84- } ) ;
80+ logger . error ( 'Failed to get routing configuration' , error ) ;
8581 }
8682
8783 if ( ! data ) return undefined ;
8884
8985 const result = $RoutingConfig . safeParse ( data ) ;
9086
9187 if ( ! result . success ) {
92- logger . error ( 'Invalid routing configuration object' , {
93- error : result . error ,
94- } ) ;
88+ logger . error ( 'Invalid routing configuration object' , result . error ) ;
9589 return undefined ;
9690 }
9791
@@ -116,7 +110,7 @@ export async function createRoutingConfig(
116110 ) ;
117111
118112 if ( error ) {
119- logger . error ( 'Failed to create message plan' , { error } ) ;
113+ logger . error ( 'Failed to create message plan' , error ) ;
120114 throw new Error ( 'Failed to create message plan' ) ;
121115 }
122116
@@ -140,9 +134,7 @@ export async function updateRoutingConfig(
140134 ) ;
141135
142136 if ( error ) {
143- logger . error ( 'Failed to get routing configuration' , {
144- error : error ,
145- } ) ;
137+ logger . error ( 'Failed to get routing configuration' , error ) ;
146138 return ;
147139 }
148140
@@ -151,9 +143,7 @@ export async function updateRoutingConfig(
151143 const result = $RoutingConfig . safeParse ( data ) ;
152144
153145 if ( ! result . success ) {
154- logger . error ( 'Invalid routing configuration object' , {
155- error : result . error ,
156- } ) ;
146+ logger . error ( 'Invalid routing configuration object' , result . error ) ;
157147 return undefined ;
158148 }
159149
@@ -172,11 +162,17 @@ export async function getMessagePlanTemplates(
172162 return getTemplatesByIds ( [ ...templateIds ] ) ;
173163}
174164
175- export async function getTemplatesByIds ( templateIds : string [ ] ) {
165+ export async function getTemplatesByIds (
166+ templateIds : string [ ]
167+ ) : Promise < MessagePlanTemplates > {
176168 const results = await Promise . allSettled (
177169 templateIds . map ( async ( templateId ) => {
178- const template = await getTemplate ( templateId ) ;
179- return { id : templateId , template } ;
170+ try {
171+ const template = await getTemplate ( templateId ) ;
172+ return { id : templateId , template } ;
173+ } catch ( error ) {
174+ throw { id : templateId , error } ;
175+ }
180176 } )
181177 ) ;
182178
@@ -187,7 +183,8 @@ export async function getTemplatesByIds(templateIds: string[]) {
187183 const { id, template } = result . value ;
188184 if ( template ) templates [ id ] = template ;
189185 } else {
190- // TODO: Error handling
186+ const { id, error } = result . reason ;
187+ throw new Error ( `Failed to get template for id ${ id } : ${ error } ` ) ;
191188 }
192189 }
193190
0 commit comments