mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-04-14 07:00:51 -04:00
fix(api): consistent responses from certificate/showCert (#54426)
This commit is contained in:
committed by
GitHub
parent
1183f0813a
commit
28f45b51dd
@@ -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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user