1
0
mirror of https://github.com/badges/shields.git synced 2025-04-18 19:44:04 +03:00

Fix [FreeCodeCampPoints] not found handling (#10377)

* Fix [FreeCodeCampPoints] not found handling

* Tighten schema
This commit is contained in:
Pierre-Yves Bigourdan 2024-07-22 22:36:23 +02:00 committed by GitHub
parent 2fb8e57105
commit 66d9f4da02
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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
}