Skip to content

Commit

Permalink
Fix [FreeCodeCampPoints] not found handling (#10377)
Browse files Browse the repository at this point in the history
* Fix [FreeCodeCampPoints] not found handling

* Tighten schema
  • Loading branch information
PyvesB authored Jul 22, 2024
1 parent 2fb8e57 commit 66d9f4d
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions services/freecodecamp/freecodecamp-points.service.js
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -21,7 +16,7 @@ const schema = Joi.object({
.pattern(/^[a-zA-Z0-9\-_+]*$/, {
points: Joi.number().allow(null).required(),
}),
}).optional(),
}).required(),
}).required()

/**
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 66d9f4d

Please sign in to comment.