fix(api): consistent responses from certificate/showCert (#54426)

This commit is contained in:
Oliver Eyton-Williams
2024-04-25 14:02:59 +02:00
committed by GitHub
parent 1183f0813a
commit 28f45b51dd
4 changed files with 36 additions and 49 deletions

View File

@@ -1,7 +1,4 @@
import { ErrorObject } from 'ajv';
import { certTypes } from '../../../shared/config/certification-settings';
type CertLogs = (typeof certTypes)[keyof typeof certTypes];
type FormattedError = {
type: 'error';
@@ -50,30 +47,6 @@ export const formatProjectCompletedValidation = (
};
};
/**
* Format validation errors for /project-completed.
*
* @param errors An array of validation errors.
* @returns Formatted errors that can be used in the response.
*/
export const formatCertificationValidation = (
errors: ErrorObject[]
): FormattedError => {
const error = getError(errors);
return error.instancePath === '' &&
Object.values(certTypes).includes(error.params.missingProperty as CertLogs)
? ({
type: 'error',
message:
'You have not provided the valid param for us to display the certification.'
} as const)
: ({
type: 'error',
message: 'That does not appear to be a valid certification request.'
} as const);
};
/**
* Format validation errors for /coderoad-challenge-completed.
*