Repository: freeCodeCamp/freeCodeCamp
File: api/src/routes/challenge.ts (TypeScript)

Code before:
      errorHandler(error, request, reply) {
        if (error.validation) {
          void reply.code(400);
          return formatProjectCompletedValidation(error.validation);
        } else {
          fastify.errorHandler(error, request, reply);
        }
      }
    },
    async (req, reply) => {
      try {
        const { files, id: challengeId } = req.body;
        const user = await fastify.prisma.user.findUniqueOrThrow({
          where: { id: req.session.user.id }
        });
        const challenge = {
          id: challengeId,
          files
        };

        if (!multifileCertProjectIds.includes(challengeId)) {
          void reply.code(403);
          return {
            type: 'error',
            message: 'That challenge type is not savable.'
          } as const;
        }

        const userSavedChallenges = saveUserChallengeData(
          challengeId,
          user.savedChallenges,
          challenge
        );

        await fastify.prisma.user.update({
          where: { id: user.id },
          data: {
            savedChallenges: userSavedChallenges
          }
        });

        return { savedChallenges: userSavedChallenges };
      } catch (error) {
        fastify.log.error(error);
        void reply.code(500);
        return {
          message:
            'Oops! Something went wrong. Please try again in a moment or contact support@freecodecamp.org if the error persists.',
          type: 'danger'
        } as const;
      }

Review comment (suggestion):
```suggestion
          return 'That challenge type is not savable.';
```
It's silly and we will be changing this ASAP, but the api-server really does just return a string.

Code after:
      errorHandler(error, request, reply) {
        if (error.validation) {
          void reply.code(400);
          return formatProjectCompletedValidation(error.validation);
        } else {
          fastify.errorHandler(error, request, reply);
        }
      }
    },
    async (req, reply) => {
      try {
        const { files, id: challengeId } = req.body;
        const user = await fastify.prisma.user.findUniqueOrThrow({
          where: { id: req.session.user.id }
        });
        const challenge = {
          id: challengeId,
          files
        };

        if (!multifileCertProjectIds.includes(challengeId)) {
          void reply.code(403);
          return 'That challenge type is not savable.';
        }

        const userSavedChallenges = saveUserChallengeData(
          challengeId,
          user.savedChallenges,
          challenge
        );

        await fastify.prisma.user.update({
          where: { id: user.id },
          data: {
            savedChallenges: userSavedChallenges
          }
        });

        return { savedChallenges: userSavedChallenges };
      } catch (error) {
        fastify.log.error(error);
        void reply.code(500);
        return {
          message:
            'Oops! Something went wrong. Please try again in a moment or contact support@freecodecamp.org if the error persists.',
          type: 'danger'
        } as const;
      }
    }
  );