@vandenberghinc/volt 1.1.39 → 1.1.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -127,6 +127,18 @@ export declare class SystemError extends Error {
|
|
|
127
127
|
static set_collection(opts: Pick<Collection.Opts<SystemError.Document>, "name" | "ttl"> & {
|
|
128
128
|
server: Server;
|
|
129
129
|
}): void;
|
|
130
|
+
/**
|
|
131
|
+
* Configure the newly created system error instances,
|
|
132
|
+
* assigning a global database collection and logger instance.
|
|
133
|
+
*/
|
|
134
|
+
static setup(opts: {
|
|
135
|
+
/** The initialized server instance. */
|
|
136
|
+
server: Server;
|
|
137
|
+
/** The collection options to use. */
|
|
138
|
+
collection: Pick<Collection.Opts<SystemError.Document>, "name" | "ttl">;
|
|
139
|
+
/** The logger to use, defaults to {@link Server.log}. */
|
|
140
|
+
logger?: SystemError.Logger;
|
|
141
|
+
}): void;
|
|
130
142
|
/**
|
|
131
143
|
* The generated identifier length (characters) for error IDs.
|
|
132
144
|
* Defaults to 256 to preserve existing behavior; tune per database constraints.
|
|
@@ -46,6 +46,21 @@ export class SystemError extends Error {
|
|
|
46
46
|
record_version: 1,
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Configure the newly created system error instances,
|
|
51
|
+
* assigning a global database collection and logger instance.
|
|
52
|
+
*/
|
|
53
|
+
static setup(opts) {
|
|
54
|
+
SystemError.collection = opts.server.db.collection({
|
|
55
|
+
name: opts.collection.name,
|
|
56
|
+
ttl: opts.collection.ttl,
|
|
57
|
+
indexes: [
|
|
58
|
+
{ keys: { id: 1 }, unique: true, forced: true }
|
|
59
|
+
],
|
|
60
|
+
record_version: 1,
|
|
61
|
+
});
|
|
62
|
+
SystemError.logger = opts.logger ?? opts.server.log;
|
|
63
|
+
}
|
|
49
64
|
/**
|
|
50
65
|
* The generated identifier length (characters) for error IDs.
|
|
51
66
|
* Defaults to 256 to preserve existing behavior; tune per database constraints.
|
|
@@ -151,7 +166,11 @@ export class SystemError extends Error {
|
|
|
151
166
|
/** Construct a system error & save it to the database. */
|
|
152
167
|
static async create(opts) {
|
|
153
168
|
const error = new SystemError(opts);
|
|
154
|
-
error.
|
|
169
|
+
const formatted = error.format({ colored: false });
|
|
170
|
+
console.error("[debug]", formatted);
|
|
171
|
+
if (error.logger) {
|
|
172
|
+
error.logger.error(formatted);
|
|
173
|
+
}
|
|
155
174
|
if (error.collection) {
|
|
156
175
|
await error.collection.set({ id: error.id }, error.document(), { retry: 25, });
|
|
157
176
|
}
|
|
@@ -165,7 +184,11 @@ export class SystemError extends Error {
|
|
|
165
184
|
*/
|
|
166
185
|
static create_detach(opts) {
|
|
167
186
|
const error = new SystemError(opts);
|
|
168
|
-
error.
|
|
187
|
+
const formatted = error.format({ colored: false });
|
|
188
|
+
console.error("[debug]", formatted);
|
|
189
|
+
if (error.logger) {
|
|
190
|
+
error.logger.error(formatted);
|
|
191
|
+
}
|
|
169
192
|
if (error.collection) {
|
|
170
193
|
void error.collection.set({ id: error.id }, error.document(), { retry: 25 }).catch((e) => {
|
|
171
194
|
try {
|