feat(learn): add full stack certificate md and handle errors

Co-authored-by: Mrugesh Mohapatra <1884376+raisedadead@users.noreply.github.com>
Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
This commit is contained in:
Kris Koishigawa
2020-06-03 22:11:26 +09:00
committed by Mrugesh Mohapatra
parent 2cfc28915c
commit 89d5c891e3
4 changed files with 104 additions and 26 deletions

View File

@ -6,6 +6,7 @@ import { Observable } from 'rx';
import debug from 'debug';
import { isEmail } from 'validator';
import format from 'date-fns/format';
import { reportError } from '../middlewares/sentry-error-handler.js';
import { ifNoUser401 } from '../utils/middleware';
import { observeQuery } from '../utils/rx';
@ -78,6 +79,12 @@ const successMessage = (username, name) => dedent`
Congratulations on behalf of the freeCodeCamp.org team!
`;
const failureMessage = name => dedent`
Something went wrong with the verification of ${name}, please try again.
If you continue to receive this error, you can send a message to
support@freeCodeCamp.org to get help.
`;
function ifNoSuperBlock404(req, res, next) {
const { superBlock } = req.body;
if (superBlock && superBlocks.includes(superBlock)) {
@ -302,27 +309,29 @@ function createVerifyCert(certTypeIds, app) {
[certType]: true
};
if (challenge) {
const { id, tests, challengeType } = challenge;
if (
!user[certType] &&
!isCertified(tests, user.completedChallenges)
) {
return Observable.just(notCertifiedMessage(certName));
}
updateData = {
...updateData,
completedChallenges: [
...user.completedChallenges,
{
id,
completedDate: new Date(),
challengeType
}
]
};
// certificate doesn't exist or
// connection error
if (!challenge) {
reportError(`Error claiming ${certName}`);
return Observable.just(failureMessage(certName));
}
const { id, tests, challengeType } = challenge;
if (!user[certType] && !isCertified(tests, user.completedChallenges)) {
return Observable.just(notCertifiedMessage(certName));
}
updateData = {
...updateData,
completedChallenges: [
...user.completedChallenges,
{
id,
completedDate: new Date(),
challengeType
}
]
};
if (!user.name) {
return Observable.just(noNameMessage);
}