Skip to content

Commit 00eca01

Browse files
committed
live-elements-web-server: Added PublicError.
1 parent d06d0fa commit 00eca01

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

packages/live-elements-web-server/shared/errors/errors.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import CSSError from "./css-error.mjs";
2+
import PublicError from "./public-error.mjs";
23
import SourceError from "./source-error.mjs";
34
import StandardError from "./standard-error.mjs";
45
import TraceError from "./trace-error.mjs";
@@ -11,5 +12,6 @@ export default [
1112
CSSError,
1213
SourceError,
1314
TraceError,
14-
WorkerError
15+
WorkerError,
16+
PublicError
1517
]
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import StandardError from "./standard-error.mjs"
2+
3+
export default class PublicError extends StandardError{
4+
constructor(message, internal){
5+
super(message)
6+
this._internal = internal
7+
this.name = this.constructor.name
8+
}
9+
10+
get internal(){ return this._internal }
11+
12+
toJSON(){
13+
return super.toJSON(['message'])
14+
}
15+
16+
static mask(error, message){
17+
if ( error instanceof PublicError ){
18+
return error
19+
} else {
20+
return new PublicError(message, error)
21+
}
22+
}
23+
24+
static fromInternal(error){
25+
return new PublicError(error.message, error)
26+
}
27+
28+
static fromJSON(json) {
29+
return StandardError.__fromJSON(json, PublicError)
30+
}
31+
}

0 commit comments

Comments
 (0)