Files
freeCodeCamp/api/src/utils/error-formatting.ts
Oliver Eyton-Williams 5482650dd0 feat(api): project-completed (#50701)
Co-authored-by: Mrugesh Mohapatra <1884376+raisedadead@users.noreply.github.com>
Co-authored-by: Niraj Nandish <nirajnandish@icloud.com>
2023-07-17 12:03:17 +04:00

33 lines
970 B
TypeScript

import { ErrorObject } from 'ajv';
export type FormattedError = {
type: 'error';
message:
| 'You have not provided the valid links for us to inspect your work.'
| 'That does not appear to be a valid challenge submission.'
// the next isn't generated here, but the type is more general.
| 'You have to complete the project before you can submit a URL.';
};
// This only formats invalid challenge submission for now.
export const formatValidationError = (
errors: ErrorObject[]
): FormattedError => {
if (errors.length !== 1) {
throw new Error(
'Bad Argument: the array of errors must have exactly one element.'
);
}
return errors[0]?.params.missingProperty === 'solution'
? {
type: 'error',
message:
'You have not provided the valid links for us to inspect your work.'
}
: {
type: 'error',
message: 'That does not appear to be a valid challenge submission.'
};
};