From 66d9f4da023bfbc26624d2762848b364f9719db5 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Bigourdan <10694593+PyvesB@users.noreply.github.com> Date: Mon, 22 Jul 2024 22:36:23 +0200 Subject: [PATCH] Fix [FreeCodeCampPoints] not found handling (#10377) * Fix [FreeCodeCampPoints] not found handling * Tighten schema --- .../freecodecamp/freecodecamp-points.service.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/services/freecodecamp/freecodecamp-points.service.js b/services/freecodecamp/freecodecamp-points.service.js index 54630c25ef530..bf1a16973f1fc 100644 --- a/services/freecodecamp/freecodecamp-points.service.js +++ b/services/freecodecamp/freecodecamp-points.service.js @@ -1,11 +1,6 @@ import Joi from 'joi' import { metric } from '../text-formatters.js' -import { - BaseJsonService, - InvalidResponse, - NotFound, - pathParams, -} from '../index.js' +import { BaseJsonService, InvalidResponse, pathParams } from '../index.js' /** * Validates that the schema response is what we're expecting. @@ -21,7 +16,7 @@ const schema = Joi.object({ .pattern(/^[a-zA-Z0-9\-_+]*$/, { points: Joi.number().allow(null).required(), }), - }).optional(), + }).required(), }).required() /** @@ -62,18 +57,18 @@ export default class FreeCodeCampPoints extends BaseJsonService { username, }, }, + httpErrors: { 404: 'profile not found' }, }) } static transform(response, username) { const { entities } = response - if (entities === undefined) - throw new NotFound({ prettyMessage: 'profile not found' }) - const { points } = entities.user[username] - if (points === null) throw new InvalidResponse({ prettyMessage: 'private' }) + if (points === null) { + throw new InvalidResponse({ prettyMessage: 'private' }) + } return points }