Skip to content

Commit d28fa19

Browse files
committed
fix: fix constructor
1 parent 878b949 commit d28fa19

1 file changed

Lines changed: 22 additions & 16 deletions

File tree

lib/_browser/index.js

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,32 @@ class Result {
2121
var statusText;
2222

2323
if ( typeof status !== "number" ) {
24+
25+
// Array
2426
if ( Array.isArray( status ) ) {
2527
[ status, statusText ] = status;
2628
}
2729

28-
// Result object
29-
else if ( status instanceof Result ) {
30-
statusText = status.statusText;
31-
status = status.status;
32-
}
30+
// object
31+
else if ( typeof status === "object" ) {
3332

34-
// Error
35-
else if ( status instanceof Error ) {
36-
status = 500;
37-
statusText = status.message;
38-
}
33+
// Result
34+
if ( status instanceof Result ) {
35+
statusText = status.statusText;
36+
status = status.status;
37+
}
3938

40-
// result-like object
41-
else if ( typeof status === "object" ) {
42-
status = status?.status;
43-
statusText = status?.statusText;
39+
// Error
40+
else if ( status instanceof Error ) {
41+
status = 500;
42+
statusText = status.message;
43+
}
44+
45+
// other object
46+
else {
47+
status = status.status;
48+
statusText = status.statusText;
49+
}
4450
}
4551
}
4652

@@ -321,12 +327,12 @@ class Result {
321327

322328
// protected
323329
_setStatus ( status, statusText ) {
324-
if ( typeof status !== "number" ) throw TypeError( "Status is not a number" );
330+
if ( typeof status !== "number" ) throw new TypeError( "Status is not a number" );
325331

326332
this.#status = status;
327333

328334
if ( statusText ) {
329-
if ( typeof statusText !== "string" ) throw TypeError( "Status text is not a string" );
335+
if ( typeof statusText !== "string" ) throw new TypeError( "Status text is not a string" );
330336

331337
this.#statusText = statusText;
332338
}

0 commit comments

Comments
 (0)