Error -> TypeError

This commit is contained in:
Jannis R 2020-02-04 18:47:25 +01:00
parent dfff999406
commit c1beb28b85
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
2 changed files with 9 additions and 9 deletions

View file

@ -56,7 +56,7 @@ const request = (ctx, userAgent, reqData) => {
if (profile.addChecksum || profile.addMicMac) {
if (!Buffer.isBuffer(profile.salt)) {
throw new Error('profile.salt must be a Buffer.')
throw new TypeError('profile.salt must be a Buffer.')
}
if (profile.addChecksum) {
const checksum = md5(Buffer.concat([

View file

@ -52,33 +52,33 @@ const validateProfile = (profile) => {
const type = types[key]
if (type === 'array') {
if (!Array.isArray(profile[key])) {
throw new Error(`profile.${key} must be an array.`)
throw new TypeError(`profile.${key} must be an array.`)
}
} else if (type !== typeof profile[key]) {
throw new Error(`profile.${key} must be a ${type}.`)
throw new TypeError(`profile.${key} must be a ${type}.`)
}
if (type === 'object' && profile[key] === null) {
throw new Error(`profile.${key} must not be null.`)
throw new TypeError(`profile.${key} must not be null.`)
}
}
if (!Array.isArray(profile.products)) {
throw new Error('profile.products must be an array.')
throw new TypeError('profile.products must be an array.')
}
if (profile.products.length === 0) throw new Error('profile.products is empty.')
for (let product of profile.products) {
if ('string' !== typeof product.id) {
throw new Error('profile.products[].id must be a string.')
throw new TypeError('profile.products[].id must be a string.')
}
if ('boolean' !== typeof product.default) {
throw new Error('profile.products[].default must be a boolean.')
throw new TypeError('profile.products[].default must be a boolean.')
}
if (!Array.isArray(product.bitmasks)) {
throw new Error(product.id + '.bitmasks must be an array.')
throw new TypeError(product.id + '.bitmasks must be an array.')
}
for (let bitmask of product.bitmasks) {
if ('number' !== typeof bitmask) {
throw new Error(product.id + '.bitmasks[] must be a number.')
throw new TypeError(product.id + '.bitmasks[] must be a number.')
}
}
}