implement error types for disposal patterns
This commit is contained in:
parent
b013649a41
commit
c4866c9712
1 changed files with 40 additions and 0 deletions
40
packages/backend/src/misc/errors/DisposeError.ts
Normal file
40
packages/backend/src/misc/errors/DisposeError.ts
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: hazelnoot and other Sharkey contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
/**
|
||||
* Common base class for DisposedError and DisposingError - please use only for catch() blocks.
|
||||
*/
|
||||
export abstract class DisposeError extends Error {
|
||||
public readonly source: string | undefined;
|
||||
|
||||
protected constructor(opts?: { source?: string, message?: string }) {
|
||||
super();
|
||||
this.source = opts?.source;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Thrown when an attempt is made to use an object that has been disposed.
|
||||
*/
|
||||
export class DisposedError extends DisposeError {
|
||||
constructor(opts?: { source?: string, message?: string }) {
|
||||
super({
|
||||
source: opts?.source,
|
||||
message: opts?.message ?? `${opts?.source ?? 'Object'} has been disposed`,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Thrown when an object is use begins disposing.
|
||||
*/
|
||||
export class DisposingError extends DisposeError {
|
||||
constructor(opts?: { source?: string, message?: string }) {
|
||||
super({
|
||||
source: opts?.source,
|
||||
message: opts?.message ?? `${opts?.source ?? 'Object'} is being disposed`,
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue