Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: error handling for endorsement flow #557

Merged
merged 2 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion apps/api-gateway/src/issuance/issuance.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,6 @@ export class IssuanceController {
@Res() res: Response
): Promise<Response> {
issueCredentialDto.type = 'Issuance';
this.logger.debug(`issueCredentialDto ::: ${JSON.stringify(issueCredentialDto)}`);

const getCredentialDetails = await this.issueCredentialService.getIssueCredentialWebhook(issueCredentialDto, id).catch(error => {
this.logger.debug(`error in saving issuance webhook ::: ${JSON.stringify(error)}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,6 @@ export class VerificationController {
@Res() res: Response
): Promise<Response> {
proofPresentationPayload.type = 'Verification';
this.logger.debug(`proofPresentationPayload ::: ${JSON.stringify(proofPresentationPayload)}`);

const webhookProofPresentation = await this.verificationService.webhookProofPresentation(orgId, proofPresentationPayload).catch(error => {
this.logger.debug(`error in saving verification webhook ::: ${JSON.stringify(error)}`);
Expand Down
20 changes: 20 additions & 0 deletions apps/ecosystem/src/ecosystem.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,26 @@ export class EcosystemRepository {
}
}

async schemaExist(schemaName: string, schemaVersion: string): Promise<schema[]> {
try {
return this.prisma.schema.findMany({
where: {
name: {
contains: schemaName,
mode: 'insensitive'
},
version: {
contains: schemaVersion,
mode: 'insensitive'
}
}
});
} catch (error) {
this.logger.error(`Error in schemaExists: ${error}`);
throw error;
}
}

// eslint-disable-next-line camelcase
async saveCredDef(credDefResult: saveCredDef): Promise<credential_definition> {
try {
Expand Down
26 changes: 21 additions & 5 deletions apps/ecosystem/src/ecosystem.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ export class EcosystemService {
this.logger.log(`alreadySchemaExist ::: ${JSON.stringify(alreadySchemaExist.length)}`);

if (0 !== alreadySchemaExist.length) {
throw new BadRequestException(ResponseMessages.ecosystem.error.schemaAlreadyExist);
throw new ConflictException(ResponseMessages.ecosystem.error.schemaAlreadyExist);
}

const getEcosystemLeadDetails = await this.ecosystemRepository.getEcosystemLeadDetails(ecosystemId);
Expand Down Expand Up @@ -1321,11 +1321,13 @@ export class EcosystemService {

async submitTransaction(transactionPayload: TransactionPayload): Promise<object> {
try {
const { endorsementId, ecosystemId, ecosystemLeadAgentEndPoint, orgId } = transactionPayload;
const { endorsementId, ecosystemId, ecosystemLeadAgentEndPoint, orgId } = transactionPayload;
const endorsementTransactionPayload = await this.ecosystemRepository.getEndorsementTransactionById(
endorsementId,
endorsementTransactionStatus.SIGNED
);


if (!endorsementTransactionPayload) {
throw new InternalServerErrorException(ResponseMessages.ecosystem.error.invalidTransaction);
}
Expand Down Expand Up @@ -1353,6 +1355,19 @@ export class EcosystemService {
ecosystemMemberDetails,
ecosystemLeadAgentDetails
);

const isSchemaExists = await this.ecosystemRepository.schemaExist(
payload.schema.name,
payload.schema.version
);

if (0 !== isSchemaExists.length) {
this.logger.error(ResponseMessages.ecosystem.error.schemaAlreadyExist);
throw new ConflictException(
ResponseMessages.ecosystem.error.schemaAlreadyExist,
{ cause: new Error(), description: ResponseMessages.errorMessages.conflict }
);
}

let apiKey: string = await this.cacheService.get(CommonConstants.CACHE_APIKEY_KEY);
if (!apiKey || null === apiKey || undefined === apiKey) {
Expand Down Expand Up @@ -1407,7 +1422,7 @@ export class EcosystemService {
throw new InternalServerErrorException(ResponseMessages.ecosystem.error.updateCredDefId);
}
return this.handleCredDefSubmission(
endorsementTransactionPayload,
endorsementTransactionPayload,
ecosystemMemberDetails,
submitTransactionRequest
);
Expand Down Expand Up @@ -1442,11 +1457,12 @@ export class EcosystemService {
const message = await this.ecosystemServiceProxy.send<any>(pattern, payload).toPromise();
return { message };
} catch (error) {
this.logger.error(`catch: ${JSON.stringify(error)}`);
this.logger.error(` agent-submit-transaction catch: ${JSON.stringify(error)}`);
throw new HttpException(
{
status: error.status,
error: error.message
message: error.message,
error: error.error
},
error.status
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export class CredentialDefinitionService extends BaseService {
const getAgentDetails = await this.credentialDefinitionRepository.getAgentType(credDef.orgId);
// const apiKey = await this._getOrgAgentApiKey(credDef.orgId);
let apiKey:string = await this.cacheService.get(CommonConstants.CACHE_APIKEY_KEY);
this.logger.log(`cachedApiKey----${apiKey}`);
if (!apiKey || null === apiKey || undefined === apiKey) {
apiKey = await this._getOrgAgentApiKey(credDef.orgId);
}
Expand Down Expand Up @@ -184,7 +183,7 @@ export class CredentialDefinitionService extends BaseService {
const orgAgentType = await this.credentialDefinitionRepository.getOrgAgentType(getAgentDetails.org_agents[0].orgAgentTypeId);
// const apiKey = await this._getOrgAgentApiKey(String(orgId));
let apiKey:string = await this.cacheService.get(CommonConstants.CACHE_APIKEY_KEY);
this.logger.log(`cachedApiKey----${apiKey}`);

if (!apiKey || null === apiKey || undefined === apiKey) {
apiKey = await this._getOrgAgentApiKey(String(orgId));
}
Expand Down
9 changes: 1 addition & 8 deletions apps/verification/src/verification.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ export class VerificationService {
const verificationMethodLabel = 'request-proof';
const url = await this.getAgentUrl(verificationMethodLabel, orgAgentType, getAgentDetails?.agentEndPoint, getAgentDetails?.tenantId);
let apiKey: string = await this.cacheService.get(CommonConstants.CACHE_APIKEY_KEY);
this.logger.log(`cachedApiKey----${apiKey}`);
if (!apiKey || null === apiKey || undefined === apiKey) {
apiKey = await this._getOrgAgentApiKey(requestProof.orgId);
}
Expand Down Expand Up @@ -336,7 +335,6 @@ export class VerificationService {
async sendOutOfBandPresentationRequest(outOfBandRequestProof: ISendProofRequestPayload, user: IUserRequest): Promise<boolean|object> {
try {

this.logger.log(`-------outOfBandRequestProof------${JSON.stringify(outOfBandRequestProof)}`);
outOfBandRequestProof.protocolVersion = outOfBandRequestProof.protocolVersion || 'v1';
outOfBandRequestProof.autoAcceptProof = outOfBandRequestProof.autoAcceptProof || 'always';

Expand All @@ -357,7 +355,6 @@ export class VerificationService {
let apiKey: string = await this.cacheService.get(CommonConstants.CACHE_APIKEY_KEY);
const verificationMethodLabel = 'create-request-out-of-band';
const url = await this.getAgentUrl(verificationMethodLabel, orgAgentType, getAgentDetails?.agentEndPoint, getAgentDetails?.tenantId);
this.logger.log(`cachedApiKey----${apiKey}`);
if (!apiKey || null === apiKey || undefined === apiKey) {
apiKey = await this._getOrgAgentApiKey(user.orgId);
}
Expand All @@ -369,7 +366,6 @@ export class VerificationService {
};

const getProofPresentation = await this._sendOutOfBandProofRequest(payload);
this.logger.log(`-----getProofPresentation---${JSON.stringify(getProofPresentation)}`);
if (!getProofPresentation) {
throw new Error(ResponseMessages.verification.error.proofPresentationNotFound);
}
Expand All @@ -393,14 +389,12 @@ export class VerificationService {

private async generateOOBProofReq(payload: IProofRequestPayload, getAgentDetails: org_agents): Promise<object> {
let agentApiKey: string = await this.cacheService.get(CommonConstants.CACHE_APIKEY_KEY);
this.logger.log(`cachedApiKey----${agentApiKey}`);
if (!agentApiKey || null === agentApiKey || undefined === agentApiKey) {
agentApiKey = await this._getOrgAgentApiKey(getAgentDetails.orgId);
}
payload.apiKey = agentApiKey;
const getProofPresentation = await this._sendOutOfBandProofRequest(payload);

this.logger.log(`-----getProofPresentation---${JSON.stringify(getProofPresentation)}`);

if (!getProofPresentation) {
throw new Error(ResponseMessages.verification.error.proofPresentationNotFound);
Expand Down Expand Up @@ -439,7 +433,6 @@ export class VerificationService {

async sendOutOfBandProofRequest(payload: IProofRequestPayload, email: string, getAgentDetails: org_agents, organizationDetails: organisation): Promise<boolean> {
let agentApiKey: string = await this.cacheService.get(CommonConstants.CACHE_APIKEY_KEY);
this.logger.log(`cachedApiKey----${agentApiKey}`);
if (!agentApiKey || null === agentApiKey || undefined === agentApiKey) {
agentApiKey = await this._getOrgAgentApiKey(getAgentDetails.orgId);
}
Expand Down Expand Up @@ -674,7 +667,7 @@ export class VerificationService {
const orgAgentType = await this.verificationRepository.getOrgAgentType(getAgentDetails?.orgAgentTypeId);
const url = await this.getAgentUrl(verificationMethodLabel, orgAgentType, getAgentDetails?.agentEndPoint, getAgentDetails?.tenantId, '', proofId);
let apiKey: string = await this.cacheService.get(CommonConstants.CACHE_APIKEY_KEY);
this.logger.log(`cachedApiKey----${apiKey}`);

if (!apiKey || null === apiKey || undefined === apiKey) {
apiKey = await this._getOrgAgentApiKey(orgId);
}
Expand Down
2 changes: 0 additions & 2 deletions libs/client-registration/src/client-registration.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ export class ClientRegistrationService {
`${process.env.KEYCLOAK_DOMAIN}admin/realms/${process.env.KEYCLOAK_REALM}/users/${payload['sub']}`,
this.getAuthHeader(token)
);
this.logger.debug(`keycloak user ${JSON.stringify(userInfoResponse)}`);
return userInfoResponse.data;
} catch (error) {
this.logger.error(`[getUserInfo]: ${JSON.stringify(error)}`);
Expand Down Expand Up @@ -236,7 +235,6 @@ export class ClientRegistrationService {
this.getAuthHeader(token)
);

this.logger.debug(`Existing apps response ${JSON.stringify(response)}`);

return {
clientId: client_id,
Expand Down