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(signature-collection): try catch not found #16447

Merged
merged 3 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
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)
}
alexdiljar marked this conversation as resolved.
Show resolved Hide resolved

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
alexdiljar marked this conversation as resolved.
Show resolved Hide resolved
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',
}
Loading