A social knowledge tool for researchers built on ATProto

update app error and use case error

+8 -4
+3 -3
src/shared/core/AppError.ts
··· 2 2 import { UseCaseError } from './UseCaseError'; 3 3 4 4 export namespace AppError { 5 - export class UnexpectedError extends Err<any, UseCaseError> { 5 + export class UnexpectedError extends UseCaseError { 6 6 message: string; 7 7 public constructor(err: any) { 8 - super(Error(`An unexpected error occurred.`)); 8 + super(`An unexpected error occurred.`); 9 9 console.log(`[AppError]: An unexpected error occurred`); 10 10 console.error(err); 11 - this.message = JSON.stringify(err); 11 + this.message = err.toString ? err.toString() : JSON.stringify(err); 12 12 } 13 13 14 14 public static create(err: any): UnexpectedError {
+5 -1
src/shared/core/UseCaseError.ts
··· 1 - interface IUseCaseError { 1 + interface IUseCaseError extends Error { 2 2 message: string; 3 3 } 4 4 5 5 export abstract class UseCaseError implements IUseCaseError { 6 6 public readonly message: string; 7 + public name: string = 'UseCaseError'; 7 8 8 9 constructor(message: string) { 9 10 this.message = message; 11 + } 12 + toString(): string { 13 + return `${this.constructor.name}: ${this.message}`; 10 14 } 11 15 }