tangled
alpha
login
or
join now
cosmik.network
/
semble
44
fork
atom
A social knowledge tool for researchers built on ATProto
44
fork
atom
overview
issues
13
pulls
pipelines
update app error and use case error
Wesley Finck
5 months ago
f4686b62
a6f57ec1
+8
-4
2 changed files
expand all
collapse all
unified
split
src
shared
core
AppError.ts
UseCaseError.ts
+3
-3
src/shared/core/AppError.ts
···
2
import { UseCaseError } from './UseCaseError';
3
4
export namespace AppError {
5
-
export class UnexpectedError extends Err<any, UseCaseError> {
6
message: string;
7
public constructor(err: any) {
8
-
super(Error(`An unexpected error occurred.`));
9
console.log(`[AppError]: An unexpected error occurred`);
10
console.error(err);
11
-
this.message = JSON.stringify(err);
12
}
13
14
public static create(err: any): UnexpectedError {
···
2
import { UseCaseError } from './UseCaseError';
3
4
export namespace AppError {
5
+
export class UnexpectedError extends UseCaseError {
6
message: string;
7
public constructor(err: any) {
8
+
super(`An unexpected error occurred.`);
9
console.log(`[AppError]: An unexpected error occurred`);
10
console.error(err);
11
+
this.message = err.toString ? err.toString() : JSON.stringify(err);
12
}
13
14
public static create(err: any): UnexpectedError {
+5
-1
src/shared/core/UseCaseError.ts
···
1
-
interface IUseCaseError {
2
message: string;
3
}
4
5
export abstract class UseCaseError implements IUseCaseError {
6
public readonly message: string;
0
7
8
constructor(message: string) {
9
this.message = message;
0
0
0
10
}
11
}
···
1
+
interface IUseCaseError extends Error {
2
message: string;
3
}
4
5
export abstract class UseCaseError implements IUseCaseError {
6
public readonly message: string;
7
+
public name: string = 'UseCaseError';
8
9
constructor(message: string) {
10
this.message = message;
11
+
}
12
+
toString(): string {
13
+
return `${this.constructor.name}: ${this.message}`;
14
}
15
}