mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 15:19:35 +02:00
Error -> TypeError
This commit is contained in:
parent
dfff999406
commit
c1beb28b85
2 changed files with 9 additions and 9 deletions
|
@ -56,7 +56,7 @@ const request = (ctx, userAgent, reqData) => {
|
||||||
|
|
||||||
if (profile.addChecksum || profile.addMicMac) {
|
if (profile.addChecksum || profile.addMicMac) {
|
||||||
if (!Buffer.isBuffer(profile.salt)) {
|
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) {
|
if (profile.addChecksum) {
|
||||||
const checksum = md5(Buffer.concat([
|
const checksum = md5(Buffer.concat([
|
||||||
|
|
|
@ -52,33 +52,33 @@ const validateProfile = (profile) => {
|
||||||
const type = types[key]
|
const type = types[key]
|
||||||
if (type === 'array') {
|
if (type === 'array') {
|
||||||
if (!Array.isArray(profile[key])) {
|
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]) {
|
} 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) {
|
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)) {
|
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.')
|
if (profile.products.length === 0) throw new Error('profile.products is empty.')
|
||||||
for (let product of profile.products) {
|
for (let product of profile.products) {
|
||||||
if ('string' !== typeof product.id) {
|
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) {
|
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)) {
|
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) {
|
for (let bitmask of product.bitmasks) {
|
||||||
if ('number' !== typeof bitmask) {
|
if ('number' !== typeof bitmask) {
|
||||||
throw new Error(product.id + '.bitmasks[] must be a number.')
|
throw new TypeError(product.id + '.bitmasks[] must be a number.')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue