5
5
BrowserError ,
6
6
BrowserErrorCode ,
7
7
} from './types.js' ;
8
+ import { errorToString } from '../../utils/errorToString.js' ;
8
9
9
10
export class PageController {
10
11
constructor ( private page : Page ) { }
@@ -27,13 +28,14 @@ export class PageController {
27
28
}
28
29
}
29
30
30
- private validateSelector ( selector : string , type : SelectorType ) : void {
31
+ private validateSelector ( selector : string , _type : SelectorType ) : void {
31
32
if ( ! selector ) {
32
33
throw new BrowserError (
33
34
'Invalid selector: empty string' ,
34
35
BrowserErrorCode . SELECTOR_INVALID ,
35
36
) ;
36
37
}
38
+ // TODO: Add more validation
37
39
}
38
40
39
41
async waitForSelector (
@@ -51,7 +53,7 @@ export class PageController {
51
53
} ) ;
52
54
} catch ( error ) {
53
55
throw new BrowserError (
54
- `Failed to find element: ${ error } ` ,
56
+ `Failed to find element: ${ errorToString ( error ) } ` ,
55
57
BrowserErrorCode . ELEMENT_NOT_FOUND ,
56
58
error ,
57
59
) ;
@@ -67,7 +69,7 @@ export class PageController {
67
69
await locator . click ( { timeout : options . timeout } ) ;
68
70
} catch ( error ) {
69
71
throw new BrowserError (
70
- `Failed to click element: ${ error } ` ,
72
+ `Failed to click element: ${ errorToString ( error ) } ` ,
71
73
BrowserErrorCode . SELECTOR_ERROR ,
72
74
error ,
73
75
) ;
@@ -87,7 +89,7 @@ export class PageController {
87
89
await locator . fill ( text , { timeout : options . timeout } ) ;
88
90
} catch ( error ) {
89
91
throw new BrowserError (
90
- `Failed to type text: ${ error } ` ,
92
+ `Failed to type text: ${ errorToString ( error ) } ` ,
91
93
BrowserErrorCode . SELECTOR_ERROR ,
92
94
error ,
93
95
) ;
@@ -106,7 +108,7 @@ export class PageController {
106
108
return ( await locator . textContent ( ) ) || '' ;
107
109
} catch ( error ) {
108
110
throw new BrowserError (
109
- `Failed to get text: ${ error } ` ,
111
+ `Failed to get text: ${ errorToString ( error ) } ` ,
110
112
BrowserErrorCode . SELECTOR_ERROR ,
111
113
error ,
112
114
) ;
0 commit comments