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:
parent
2fb8e57105
commit
66d9f4da02
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user