mirror of
https://codeberg.org/timelimit/timelimit-server.git
synced 2026-08-31 19:03:45 +02:00
Refactor exception usage
This commit is contained in:
+5
-1
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
|
||||
import * as TokenGenerator from 'tokgen'
|
||||
import { ValidationException } from '../exception'
|
||||
|
||||
const authTokenGenerator = new TokenGenerator({
|
||||
length: 32,
|
||||
@@ -33,7 +34,10 @@ export const generateIdWithinFamily = () => idWithinFamilyGenerator.generate()
|
||||
export const isIdWithinFamily = (id: string) => id.length === 6 && /^[a-zA-Z0-9]+$/.test(id)
|
||||
export const assertIdWithinFamily = (id: string) => {
|
||||
if (!isIdWithinFamily(id)) {
|
||||
throw new Error('invalid id within family')
|
||||
throw new ValidationException({
|
||||
staticMessage: 'invalid id within family',
|
||||
dynamicMessage: 'invalid id within family: ' + id
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user