Skip to content

Commit

Permalink
fix(signature-collection): try catch not found (#16447)
Browse files Browse the repository at this point in the history
* fix: error in application

* chore: nx format:write update dirty files

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: andes-it <builders@andes.is>
  • Loading branch information
3 people authored Oct 17, 2024
1 parent 342c2d8 commit 17e1369
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,41 +36,43 @@ export class ParliamentaryListSigningService extends BaseTemplateApiService {
}

async canSign({ auth }: TemplateApiModuleActionProps) {
let signee
try {
const signee = await this.signatureCollectionClientService.getSignee(auth)
const { canSign, canSignInfo } = signee
if (canSign) {
return signee
}
if (!canSignInfo) {
// canCreateInfo will always be defined if canCreate is false but we need to check for typescript
throw new TemplateApiError(errorMessages.deniedByService, 400)
}
const errors: ProviderErrorReason[] = canSignInfo?.map((key) => {
switch (key) {
case ReasonKey.UnderAge:
return errorMessages.age
case ReasonKey.NoCitizenship:
return errorMessages.citizenship
case ReasonKey.NotISResidency:
return errorMessages.residency
case ReasonKey.CollectionNotOpen:
return errorMessages.active
case ReasonKey.AlreadySigned:
return errorMessages.signer
case ReasonKey.noInvalidSignature:
return errorMessages.invalidSignature
default:
return errorMessages.deniedByService
}
})
throw new TemplateApiError(errors, 405)
} catch (error) {
if (error.status === 404) {
throw new TemplateApiError(errorMessages.singeeNotFound, 404)
}
signee = await this.signatureCollectionClientService.getSignee(auth)
} catch (e) {
throw new TemplateApiError(errorMessages.singeeNotFound, 404)
}

const { canSign, canSignInfo } = signee
if (canSign) {
return signee
}
if (!canSignInfo) {
// canCreateInfo will always be defined if canCreate is false but we need to check for typescript
throw new TemplateApiError(errorMessages.deniedByService, 400)
}
const errors: ProviderErrorReason[] = canSignInfo?.map((key) => {
switch (key) {
case ReasonKey.UnderAge:
return errorMessages.age
case ReasonKey.NoCitizenship:
return errorMessages.citizenship
case ReasonKey.NotISResidency:
return errorMessages.residency
case ReasonKey.CollectionNotOpen:
return errorMessages.active
case ReasonKey.AlreadySigned:
return errorMessages.signer
case ReasonKey.noInvalidSignature:
return errorMessages.invalidSignature
case ReasonKey.notFound:
return errorMessages.singeeNotFound

default:
return errorMessages.deniedByService
}
})
throw new TemplateApiError(errors, 405)
}

async getList({ auth, application }: TemplateApiModuleActionProps) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,5 @@ export enum ReasonKey {
AlreadySigned = 'alreadySigned',
NotOwner = 'notOwner',
noInvalidSignature = 'noInvalidSignature',
notFound = 'notFound',
}

0 comments on commit 17e1369

Please sign in to comment.