diff --git a/libs/application/template-api-modules/src/lib/modules/templates/signature-collection/parliamentary-list-signing/parliamentary-list-signing.service.ts b/libs/application/template-api-modules/src/lib/modules/templates/signature-collection/parliamentary-list-signing/parliamentary-list-signing.service.ts index 45116709c2fb..8e1ac1e1c5f3 100644 --- a/libs/application/template-api-modules/src/lib/modules/templates/signature-collection/parliamentary-list-signing/parliamentary-list-signing.service.ts +++ b/libs/application/template-api-modules/src/lib/modules/templates/signature-collection/parliamentary-list-signing/parliamentary-list-signing.service.ts @@ -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) { diff --git a/libs/clients/signature-collection/src/lib/signature-collection.types.ts b/libs/clients/signature-collection/src/lib/signature-collection.types.ts index 0a0b2ae5401a..42fa69f46cf6 100644 --- a/libs/clients/signature-collection/src/lib/signature-collection.types.ts +++ b/libs/clients/signature-collection/src/lib/signature-collection.types.ts @@ -106,4 +106,5 @@ export enum ReasonKey { AlreadySigned = 'alreadySigned', NotOwner = 'notOwner', noInvalidSignature = 'noInvalidSignature', + notFound = 'notFound', }