@@ -407,11 +407,11 @@ export class Controller {
407
407
) : Promise < void > {
408
408
const { providerConfig } = req ;
409
409
410
- if ( ! providerConfig ) {
411
- throw new ServerError ( 400 , 'Missing parameters' ) ;
412
- }
413
-
414
410
try {
411
+ if ( ! providerConfig ) {
412
+ throw new ServerError ( 400 , 'Missing parameters' ) ;
413
+ }
414
+
415
415
infoLogger ( 'getContactsDelta' , 'START' , providerConfig . apiKey ) ;
416
416
417
417
const fetchContactsDelta = async ( ) : Promise < ContactDelta > => {
@@ -461,7 +461,7 @@ export class Controller {
461
461
errorLogger (
462
462
'getContacts' ,
463
463
'Could not get contacts:' ,
464
- providerConfig . apiKey ,
464
+ providerConfig ? .apiKey ,
465
465
error ,
466
466
) ;
467
467
next ( error ) ;
@@ -474,26 +474,25 @@ export class Controller {
474
474
next : NextFunction ,
475
475
) : Promise < void > {
476
476
const { providerConfig } = req ;
477
+ try {
478
+ if ( ! providerConfig ) {
479
+ throw new ServerError ( 400 , 'Missing parameters' ) ;
480
+ }
477
481
478
- if ( ! providerConfig ) {
479
- throw new ServerError ( 400 , 'Missing parameters' ) ;
480
- }
481
-
482
- if ( ! this . adapter . getContact ) {
483
- throw new ServerError ( 501 , 'Getting single contact is not implemented' ) ;
484
- }
482
+ if ( ! this . adapter . getContact ) {
483
+ throw new ServerError ( 501 , 'Getting single contact is not implemented' ) ;
484
+ }
485
485
486
- infoLogger ( 'getContact' , 'START' , providerConfig . apiKey ) ;
486
+ infoLogger ( 'getContact' , 'START' , providerConfig . apiKey ) ;
487
487
488
- const contactType : IntegrationEntityType | undefined = Object . values (
489
- IntegrationEntityType ,
490
- ) . find ( ( value ) => value === req . query . type ?. toString ( ) ) ;
488
+ const contactType : IntegrationEntityType | undefined = Object . values (
489
+ IntegrationEntityType ,
490
+ ) . find ( ( value ) => value === req . query . type ?. toString ( ) ) ;
491
491
492
- if ( ! contactType ) {
493
- throw new ServerError ( 400 , 'Missing contact type query parameter' ) ;
494
- }
492
+ if ( ! contactType ) {
493
+ throw new ServerError ( 400 , 'Missing contact type query parameter' ) ;
494
+ }
495
495
496
- try {
497
496
const contactId = req . params . id ;
498
497
infoLogger (
499
498
'getContact' ,
@@ -522,7 +521,7 @@ export class Controller {
522
521
errorLogger (
523
522
'getContact' ,
524
523
'Could not get contact:' ,
525
- providerConfig . apiKey ,
524
+ providerConfig ? .apiKey ,
526
525
error ,
527
526
) ;
528
527
next ( error ) ;
@@ -1364,17 +1363,18 @@ export class Controller {
1364
1363
next : NextFunction ,
1365
1364
) : Promise < void > {
1366
1365
const { providerConfig } = req ;
1367
- if ( ! providerConfig ) {
1368
- throw new ServerError ( 400 , 'Missing parameters' ) ;
1369
- }
1370
1366
1371
- if ( ! this . adapter . getAccountId ) {
1372
- throw new ServerError ( 501 , 'Fetching account id is not implemented' ) ;
1373
- }
1367
+ try {
1368
+ if ( ! providerConfig ) {
1369
+ throw new ServerError ( 400 , 'Missing parameters' ) ;
1370
+ }
1374
1371
1375
- infoLogger ( 'getAccountId' , 'START' , providerConfig . apiKey ) ;
1372
+ if ( ! this . adapter . getAccountId ) {
1373
+ throw new ServerError ( 501 , 'Fetching account id is not implemented' ) ;
1374
+ }
1375
+
1376
+ infoLogger ( 'getAccountId' , 'START' , providerConfig . apiKey ) ;
1376
1377
1377
- try {
1378
1378
const accountId = await this . adapter . getAccountId ( providerConfig ) ;
1379
1379
1380
1380
if ( ! accountId ) {
@@ -1399,36 +1399,24 @@ export class Controller {
1399
1399
res : Response ,
1400
1400
next : NextFunction ,
1401
1401
) : Promise < void > {
1402
- if ( ! this . adapter . handleWebhook ) {
1403
- throw new ServerError ( 501 , 'Webhook handling not implemented' ) ;
1404
- }
1405
-
1406
- if ( ! this . adapter . verifyWebhookRequest ) {
1407
- throw new ServerError ( 501 , 'Webhook verification not implemented' ) ;
1408
- }
1402
+ try {
1403
+ if ( ! this . adapter . handleWebhook ) {
1404
+ throw new ServerError ( 501 , 'Webhook handling not implemented' ) ;
1405
+ }
1409
1406
1410
- let verified : boolean ;
1407
+ if ( ! this . adapter . verifyWebhookRequest ) {
1408
+ throw new ServerError ( 501 , 'Webhook verification not implemented' ) ;
1409
+ }
1411
1410
1412
- try {
1413
- verified = await this . adapter . verifyWebhookRequest ( req ) ;
1414
- } catch ( error ) {
1415
- errorLogger (
1416
- 'handleWebhook' ,
1417
- 'Error while verifying webhook request:' ,
1418
- '' ,
1419
- error || 'Unknown' ,
1420
- ) ;
1421
- throw new ServerError ( 403 , 'Webhook verification failed' ) ;
1422
- }
1411
+ const verified = await this . adapter . verifyWebhookRequest ( req ) ;
1423
1412
1424
- if ( ! verified ) {
1425
- errorLogger ( 'handleWebhook' , 'Webhook verification failed' , '' ) ;
1426
- throw new ServerError ( 403 , 'Webhook verification failed' ) ;
1427
- }
1413
+ if ( ! verified ) {
1414
+ errorLogger ( 'handleWebhook' , 'Webhook verification failed' , '' ) ;
1415
+ throw new ServerError ( 403 , 'Webhook verification failed' ) ;
1416
+ }
1428
1417
1429
- infoLogger ( 'handleWebhook' , 'START' , '' ) ;
1418
+ infoLogger ( 'handleWebhook' , 'START' , '' ) ;
1430
1419
1431
- try {
1432
1420
const changeEvents : ContactChangeEvent [ ] =
1433
1421
await this . adapter . handleWebhook ( req ) ;
1434
1422
0 commit comments