main
Last change
on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 5 days ago |
F4 Finalna Verzija
|
-
Property mode
set to
100644
|
File size:
1.2 KB
|
Rev | Line | |
---|
[79a0317] | 1 | /*
|
---|
| 2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
---|
| 3 | */
|
---|
| 4 |
|
---|
| 5 | "use strict";
|
---|
| 6 |
|
---|
| 7 | /** @typedef {import("./ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
---|
| 8 | /** @typedef {import("./ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
---|
| 9 |
|
---|
| 10 | class ErrorObjectSerializer {
|
---|
| 11 | /**
|
---|
| 12 | * @param {ErrorConstructor | EvalErrorConstructor | RangeErrorConstructor | ReferenceErrorConstructor | SyntaxErrorConstructor | TypeErrorConstructor} Type error type
|
---|
| 13 | */
|
---|
| 14 | constructor(Type) {
|
---|
| 15 | this.Type = Type;
|
---|
| 16 | }
|
---|
| 17 |
|
---|
| 18 | /**
|
---|
| 19 | * @param {Error | EvalError | RangeError | ReferenceError | SyntaxError | TypeError} obj error
|
---|
| 20 | * @param {ObjectSerializerContext} context context
|
---|
| 21 | */
|
---|
| 22 | serialize(obj, context) {
|
---|
| 23 | context.write(obj.message);
|
---|
| 24 | context.write(obj.stack);
|
---|
| 25 | context.write(/** @type {Error & { cause: "unknown" }} */ (obj).cause);
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | /**
|
---|
| 29 | * @param {ObjectDeserializerContext} context context
|
---|
| 30 | * @returns {Error | EvalError | RangeError | ReferenceError | SyntaxError | TypeError} error
|
---|
| 31 | */
|
---|
| 32 | deserialize(context) {
|
---|
| 33 | const err = new this.Type();
|
---|
| 34 |
|
---|
| 35 | err.message = context.read();
|
---|
| 36 | err.stack = context.read();
|
---|
| 37 | /** @type {Error & { cause: "unknown" }} */
|
---|
| 38 | (err).cause = context.read();
|
---|
| 39 |
|
---|
| 40 | return err;
|
---|
| 41 | }
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | module.exports = ErrorObjectSerializer;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.