implement AbortedError to represent an aborted operation
This commit is contained in:
parent
c4866c9712
commit
73f672ff79
1 changed files with 24 additions and 0 deletions
24
packages/backend/src/misc/errors/AbortedError.ts
Normal file
24
packages/backend/src/misc/errors/AbortedError.ts
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: hazelnoot and other Sharkey contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
import { renderInlineError } from '@/misc/render-inline-error.js';
|
||||
|
||||
/**
|
||||
* Throw when an operation is unexpectedly aborted.
|
||||
*/
|
||||
export class AbortedError extends Error {
|
||||
// Fix the error name in stack traces - https://stackoverflow.com/a/71573071
|
||||
override name = this.constructor.name;
|
||||
|
||||
constructor(signal: AbortSignal, message?: string, options?: Omit<ErrorOptions, 'cause'>) {
|
||||
super(
|
||||
`Operation aborted: ${message ?? renderInlineError(signal.reason)}`,
|
||||
{
|
||||
...(options ?? {}),
|
||||
cause: signal.reason,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue