Skip to content

Commit 571a16a

Browse files
authored
Fix error name
1 parent 9291b8a commit 571a16a

File tree

2 files changed

+24
-27
lines changed

2 files changed

+24
-27
lines changed

src/lib/params-serializer.test.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import test from 'ava'
22

33
import {
44
paramsSerializer,
5-
UnserializeableParamError,
5+
UnserializableParamError,
66
} from './params-serializer.js'
77

88
test('serializes empty object', (t) => {
@@ -54,38 +54,38 @@ test('serializes array params with many values', (t) => {
5454
)
5555
})
5656

57-
test('cannot serialize unserializeable values', (t) => {
57+
test('cannot serialize unserializable values', (t) => {
5858
t.throws(() => paramsSerializer({ foo: {} }), {
59-
instanceOf: UnserializeableParamError,
59+
instanceOf: UnserializableParamError,
6060
})
6161
t.throws(() => paramsSerializer({ foo: { x: 2 } }), {
62-
instanceOf: UnserializeableParamError,
62+
instanceOf: UnserializableParamError,
6363
})
6464
t.throws(() => paramsSerializer({ foo: () => {} }), {
65-
instanceOf: UnserializeableParamError,
65+
instanceOf: UnserializableParamError,
6666
})
6767
})
6868

69-
test('cannot serialize array params with unserializeable values', (t) => {
69+
test('cannot serialize array params with unserializable values', (t) => {
7070
t.throws(() => paramsSerializer({ bar: ['a', null] }), {
71-
instanceOf: UnserializeableParamError,
71+
instanceOf: UnserializableParamError,
7272
})
7373
t.throws(() => paramsSerializer({ bar: ['a', undefined] }), {
74-
instanceOf: UnserializeableParamError,
74+
instanceOf: UnserializableParamError,
7575
})
7676
t.throws(() => paramsSerializer({ bar: ['a', ['s']] }), {
77-
instanceOf: UnserializeableParamError,
77+
instanceOf: UnserializableParamError,
7878
})
7979
t.throws(() => paramsSerializer({ bar: ['a', []] }), {
80-
instanceOf: UnserializeableParamError,
80+
instanceOf: UnserializableParamError,
8181
})
8282
t.throws(() => paramsSerializer({ bar: ['a', {}] }), {
83-
instanceOf: UnserializeableParamError,
83+
instanceOf: UnserializableParamError,
8484
})
8585
t.throws(() => paramsSerializer({ bar: ['a', { x: 2 }] }), {
86-
instanceOf: UnserializeableParamError,
86+
instanceOf: UnserializableParamError,
8787
})
8888
t.throws(() => paramsSerializer({ bar: ['a', () => {}] }), {
89-
instanceOf: UnserializeableParamError,
89+
instanceOf: UnserializableParamError,
9090
})
9191
})

src/lib/params-serializer.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,43 +9,40 @@ export const paramsSerializer: CustomParamsSerializer = (params) => {
99
if (Array.isArray(value)) {
1010
if (value.length === 0) searchParams.set(name, '')
1111
for (const v of value) {
12-
throwIfUnserializeable(name, v)
12+
throwIfUnserializable(name, v)
1313
searchParams.append(name, v)
1414
}
1515
continue
1616
}
1717

18-
throwIfUnserializeable(name, value)
18+
throwIfUnserializable(name, value)
1919
searchParams.set(name, value)
2020
}
2121

2222
searchParams.sort()
2323
return searchParams.toString()
2424
}
2525

26-
const throwIfUnserializeable = (k, v): void => {
26+
const throwIfUnserializable = (k: string, v: unknown): void => {
2727
if (v == null) {
28-
throw new UnserializeableParamError(
29-
`Parameter ${k} is ${v} or contains ${v}`,
30-
)
28+
throw new UnserializableParamError(k, `is ${v} or contains ${v}`)
3129
}
3230

3331
if (typeof v === 'function') {
34-
throw new UnserializeableParamError(
35-
`Parameter ${k} is a function or contains a function`,
32+
throw new UnserializableParamError(
33+
k,
34+
'is a function or contains a function',
3635
)
3736
}
3837

3938
if (typeof v === 'object') {
40-
throw new UnserializeableParamError(
41-
`Parameter ${k} is an object or contains an object`,
42-
)
39+
throw new UnserializableParamError(k, 'is an object or contains an object')
4340
}
4441
}
4542

46-
export class UnserializeableParamError extends Error {
47-
constructor(message: string) {
48-
super(`Could not serialize parameter: ${message}`)
43+
export class UnserializableParamError extends Error {
44+
constructor(name: string, message: string) {
45+
super(`Could not serialize parameter: '${name}' ${message}`)
4946
this.name = this.constructor.name
5047
Error.captureStackTrace(this, this.constructor)
5148
}

0 commit comments

Comments
 (0)