From d96b7d37b22d1e6f39b35d3b8d755b1d0768cfe4 Mon Sep 17 00:00:00 2001 From: sagarkhole4 Date: Wed, 26 Jun 2024 17:28:38 +0530 Subject: [PATCH 1/3] fix: added error handling for w3c schema --- src/controllers/multi-tenancy/MultiTenancyController.ts | 9 +++++++++ src/controllers/polygon/PolygonController.ts | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/src/controllers/multi-tenancy/MultiTenancyController.ts b/src/controllers/multi-tenancy/MultiTenancyController.ts index c3b401e0..51bebd14 100644 --- a/src/controllers/multi-tenancy/MultiTenancyController.ts +++ b/src/controllers/multi-tenancy/MultiTenancyController.ts @@ -1007,6 +1007,15 @@ export class MultiTenancyController extends Controller { schema, }) }) + + if (schemaResponse.schemaState?.state === 'failed') { + const reason = schemaResponse.schemaState?.reason?.toLowerCase() + if (reason && reason.includes('insufficient') && reason.includes('funds')) { + throw new Error('Insufficient funds to the address, Please add funds to perform this operation') + } else { + throw new Error(schemaResponse.schemaState?.reason) + } + } const configFileData = fs.readFileSync('config.json', 'utf-8') const config = JSON.parse(configFileData) diff --git a/src/controllers/polygon/PolygonController.ts b/src/controllers/polygon/PolygonController.ts index 86427367..7b9a1c30 100644 --- a/src/controllers/polygon/PolygonController.ts +++ b/src/controllers/polygon/PolygonController.ts @@ -70,6 +70,15 @@ export class Polygon extends Controller { schema, }) + if (schemaResponse.schemaState?.state === 'failed') { + const reason = schemaResponse.schemaState?.reason?.toLowerCase() + if (reason && reason.includes('insufficient') && reason.includes('funds')) { + throw new Error('Insufficient funds to the address, Please add funds to perform this operation') + } else { + throw new Error(schemaResponse.schemaState?.reason) + } + } + const schemaServerConfig = fs.readFileSync('config.json', 'utf-8') const configJson = JSON.parse(schemaServerConfig) if (!configJson.schemaFileServerURL) { From 201ed3252eb7af6118623fd00555f5be8854f691 Mon Sep 17 00:00:00 2001 From: sagarkhole4 Date: Thu, 11 Jul 2024 15:02:19 +0530 Subject: [PATCH 2/3] Add feature for basic-message in MultiTenant Module --- .../multi-tenancy/MultiTenancyController.ts | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/controllers/multi-tenancy/MultiTenancyController.ts b/src/controllers/multi-tenancy/MultiTenancyController.ts index 51bebd14..fa49b8a7 100644 --- a/src/controllers/multi-tenancy/MultiTenancyController.ts +++ b/src/controllers/multi-tenancy/MultiTenancyController.ts @@ -2013,4 +2013,36 @@ export class MultiTenancyController extends Controller { return questionAnswerRecord } + + + /** + * Send a question to a connection + * + * @param tenantId Tenant identifier + * @param connectionId Connection identifier + * @param content The content of the message + */ + @Security('apiKey') + @Post('/basic-message/:connectionId/:tenantId') + public async sendBasicMessage( + @Path('connectionId') connectionId: RecordId, + @Path('tenantId') tenantId: string, + @Body() request: Record<'content', string>, + @Res() notFoundError: TsoaResponse<404, { reason: string }>, + @Res() internalServerError: TsoaResponse<500, { message: string }> + ) { + try { + let basicMessageRecord + await this.agent.modules.tenants.withTenantAgent({ tenantId }, async (tenantAgent) => { + basicMessageRecord = await tenantAgent.basicMessages.sendMessage(connectionId, request.content) + basicMessageRecord = basicMessageRecord?.toJSON() + }) + return basicMessageRecord + } catch (error) { + if (error instanceof RecordNotFoundError) { + return notFoundError(404, { reason: `connection with connection id "${connectionId}" not found.` }) + } + return internalServerError(500, { message: `something went wrong: ${error}` }) + } + } } From 9e840175df0f6bd608d729cf0f0554bec797a994 Mon Sep 17 00:00:00 2001 From: sagarkhole4 Date: Thu, 11 Jul 2024 15:02:40 +0530 Subject: [PATCH 3/3] Add feature for basic-message in MultiTenant Module --- src/controllers/multi-tenancy/MultiTenancyController.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/controllers/multi-tenancy/MultiTenancyController.ts b/src/controllers/multi-tenancy/MultiTenancyController.ts index fa49b8a7..e7c296e0 100644 --- a/src/controllers/multi-tenancy/MultiTenancyController.ts +++ b/src/controllers/multi-tenancy/MultiTenancyController.ts @@ -1007,7 +1007,7 @@ export class MultiTenancyController extends Controller { schema, }) }) - + if (schemaResponse.schemaState?.state === 'failed') { const reason = schemaResponse.schemaState?.reason?.toLowerCase() if (reason && reason.includes('insufficient') && reason.includes('funds')) { @@ -2014,7 +2014,6 @@ export class MultiTenancyController extends Controller { return questionAnswerRecord } - /** * Send a question to a connection *