Skip to content
This repository was archived by the owner on Oct 21, 2021. It is now read-only.

Commit f40c751

Browse files
committed
Rename as query error specific class
1 parent f7dda0e commit f40c751

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

index.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
type Queryable = Document | DocumentFragment | Element
44

5-
class InvariantError extends Error {
5+
class QueryError extends Error {
66
framesToPop: number
77

88
constructor(message) {
99
super(message)
10-
this.name = 'Invariant Violation'
1110
this.framesToPop = 1
1211
}
1312
}
@@ -18,7 +17,7 @@ export function closest<T: Element>(element: Element, selectors: string, type: C
1817
if (el instanceof klass) {
1918
return el
2019
}
21-
throw new InvariantError(`Element not found: <${klass.name}> ${selectors}`)
20+
throw new QueryError(`Element not found: <${klass.name}> ${selectors}`)
2221
}
2322

2423
export function query<T: Element>(context: Queryable, selectors: string, type: Class<T>): T {
@@ -27,7 +26,7 @@ export function query<T: Element>(context: Queryable, selectors: string, type: C
2726
if (el instanceof klass) {
2827
return el
2928
}
30-
throw new InvariantError(`Element not found: <${klass.name}> ${selectors}`)
29+
throw new QueryError(`Element not found: <${klass.name}> ${selectors}`)
3130
}
3231

3332
export function querySelectorAll<T: Element>(context: Queryable, selectors: string, type: Class<T>): Array<T> {
@@ -47,13 +46,13 @@ export function namedItem<T: HTMLElement>(form: HTMLFormElement, itemName: strin
4746
if (el instanceof klass) {
4847
return el
4948
}
50-
throw new InvariantError(`Element not found by name: <${klass.name}> ${itemName}`)
49+
throw new QueryError(`Element not found by name: <${klass.name}> ${itemName}`)
5150
}
5251

5352
export function getAttribute(element: Element, attributeName: string): string {
5453
const attribute = element.getAttribute(attributeName)
5554
if (attribute != null) {
5655
return attribute
5756
}
58-
throw new InvariantError(`Attribute not found on element: ${attributeName}`)
57+
throw new QueryError(`Attribute not found on element: ${attributeName}`)
5958
}

0 commit comments

Comments
 (0)