Skip to content

Commit 0c9bc16

Browse files
fix: Changes in NATS interceptor for error handling (#1103)
* fix: changes in nats intercepor for error handling Signed-off-by: pranalidhanavade <[email protected]> * fix: Error handling for send proof request with identical attributes when one attribute uses predicates and the other does not Signed-off-by: pranalidhanavade <[email protected]> * fix: Resolve comments on PR Signed-off-by: pranalidhanavade <[email protected]> * fix: added comments in service Signed-off-by: pranalidhanavade <[email protected]> * fix: added comments in service Signed-off-by: pranalidhanavade <[email protected]> --------- Signed-off-by: pranalidhanavade <[email protected]>
1 parent 073cdb8 commit 0c9bc16

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

apps/verification/src/verification.service.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,26 @@ export class VerificationService {
310310
return getProofPresentationById?.response;
311311
}
312312
} catch (error) {
313+
// Handle cases where identical attributes are used in both predicates and non-predicates.
314+
// This case is not supported in credo-ts, so we are handling in platform
315+
// TODO: Handle all credo-errors globally in platform
316+
317+
const errorMessage = error?.status?.message?.error?.message;
318+
const match = errorMessage?.match(
319+
/CredoError: The proof request contains duplicate predicates and attributes: (.+)/
320+
);
321+
if (match) {
322+
const [, duplicateAttributes] = match;
323+
throw new RpcException({
324+
message: `CredoError: The proof request contains duplicate attributes: ${duplicateAttributes}`,
325+
statusCode: 500
326+
});
327+
}
328+
313329
this.logger.error(`[sendProofRequest] - error in sending proof request: ${JSON.stringify(error)}`);
314330
this.verificationErrorHandling(error);
331+
}
315332
}
316-
}
317333

318334

319335
/**

libs/interceptors/nats.interceptor.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@ import {
1717
intercept(context: ExecutionContext, next: CallHandler): Observable<unknown> {
1818
return next.handle().pipe(
1919
catchError((error) => {
20-
if (error.message.includes(ResponseMessages.nats.error.natsConnect)) {
20+
21+
if ('string' === typeof error.message && error.message.includes(ResponseMessages.nats.error.natsConnect)) {
2122
this.logger.error(`No subscribers for message: ${error.message}`);
2223
return throwError(() => new HttpException(ResponseMessages.nats.error.noSubscribers, 500));
24+
} else if (error.message.message) {
25+
return throwError(() => new HttpException(error.message.message, error.statusCode));
2326
}
24-
return throwError(() => error);
27+
return throwError(() => error);
2528
})
2629
);
2730
}

0 commit comments

Comments
 (0)