1
1
/* eslint-disable camelcase */
2
2
import { CommonService } from '@credebl/common' ;
3
3
import { CommonConstants } from '@credebl/common/common.constant' ;
4
- import { HttpException , Inject , Injectable , Logger , NotFoundException } from '@nestjs/common' ;
4
+ import { HttpException , HttpStatus , Inject , Injectable , Logger , NotFoundException } from '@nestjs/common' ;
5
5
import { ClientProxy , RpcException } from '@nestjs/microservices' ;
6
6
import { from , map } from 'rxjs' ;
7
7
import {
@@ -466,8 +466,16 @@ export class ConnectionService {
466
466
const createConnectionInvitation = await this . _receiveInvitationUrl ( url , orgId , receiveInvitationUrl ) ;
467
467
return createConnectionInvitation . response ;
468
468
} catch ( error ) {
469
- this . logger . error ( `[receiveInvitationUrl] - error in receive invitation url : ${ JSON . stringify ( error ) } ` ) ;
469
+ this . logger . error ( `[receiveInvitationUrl] - error in receive invitation url : ${ JSON . stringify ( error , null , 2 ) } ` ) ;
470
470
471
+ const customErrorMessage = error ?. status ?. message ?. error ?. message ;
472
+ if ( customErrorMessage ) {
473
+ throw new RpcException ( {
474
+ statusCode : HttpStatus . CONFLICT ,
475
+ message : customErrorMessage ,
476
+ error : ResponseMessages . errorMessages . conflict
477
+ } ) ;
478
+ } else
471
479
if ( error ?. response ?. error ?. reason ) {
472
480
throw new RpcException ( {
473
481
message : ResponseMessages . connection . error . connectionNotFound ,
@@ -487,9 +495,22 @@ export class ConnectionService {
487
495
) : Promise < {
488
496
response ;
489
497
} > {
498
+
490
499
const pattern = { cmd : 'agent-receive-invitation-url' } ;
491
500
const payload = { url, orgId, receiveInvitationUrl } ;
492
- return this . natsCall ( pattern , payload ) ;
501
+
502
+ try {
503
+ return await this . natsCall ( pattern , payload ) ;
504
+ } catch ( error ) {
505
+ this . logger . error ( `catch: ${ JSON . stringify ( error ) } ` ) ;
506
+ throw new HttpException (
507
+ {
508
+ status : error . status ,
509
+ error : error . message
510
+ } ,
511
+ error . status
512
+ ) ;
513
+ }
493
514
}
494
515
495
516
async receiveInvitation (
0 commit comments