-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #136 from waifuvault/add-processupload-exception
Add processupload exception
- Loading branch information
Showing
8 changed files
with
123 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import type { HttpErrorRenderObj } from "../utils/typeings.js"; | ||
import { Exception } from "@tsed/exceptions"; | ||
|
||
export interface IErrorProcessorEngine<E extends Exception> { | ||
/** | ||
* Process error | ||
* @param obj | ||
*/ | ||
process(obj: HttpErrorRenderObj<E>): Promise<boolean>; | ||
|
||
/** | ||
* Returns true if this render engine supports the exception thrown by the system | ||
* @param exception | ||
*/ | ||
supportsError(exception: Exception): boolean; | ||
} |
25 changes: 25 additions & 0 deletions
25
src/engine/impl/ErrorProcessors/ProcessUploadErrorProcessorEngine.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { ERROR_PROCESSOR_ENGINE } from "../../../model/di/tokens.js"; | ||
import { Injectable, ProviderScope } from "@tsed/di"; | ||
import { Exception } from "@tsed/exceptions"; | ||
import { ProcessUploadException } from "../../../model/exceptions/ProcessUploadException.js"; | ||
import type { IErrorProcessorEngine } from "../../IErrorProcessorEngine.js"; | ||
import { HttpErrorRenderObj } from "../../../utils/typeings.js"; | ||
import { FileUtils } from "../../../utils/Utils.js"; | ||
import path from "node:path"; | ||
|
||
@Injectable({ | ||
scope: ProviderScope.SINGLETON, | ||
type: ERROR_PROCESSOR_ENGINE, | ||
}) | ||
export class ProcessUploadErrorProcessorEngine implements IErrorProcessorEngine<ProcessUploadException> { | ||
public supportsError(exception: Exception): boolean { | ||
return exception instanceof ProcessUploadException; | ||
} | ||
|
||
public async process(obj: HttpErrorRenderObj<ProcessUploadException>): Promise<boolean> { | ||
if (obj.internalError.filePath) { | ||
await FileUtils.deleteFile(path.basename(obj.internalError.filePath), true); | ||
} | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export const SQLITE_DATA_SOURCE = Symbol.for("SqliteDataSource"); | ||
export const HTTP_RENDER_ENGINE = Symbol.for("IHttpErrorRenderEngine"); | ||
export const ERROR_PROCESSOR_ENGINE = Symbol.for("IErrorProcessorEngine"); | ||
export const AV_ENGINE = Symbol.for("IAvEngine"); | ||
export const CAPTCHA_ENGINE = Symbol.for("ICaptchaEngine"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { HTTPException } from "@tsed/exceptions"; | ||
|
||
export class ProcessUploadException extends HTTPException { | ||
public constructor( | ||
status: number, | ||
message?: string, | ||
public filePath?: string, | ||
origin?: Error | string, | ||
) { | ||
super(status, message, origin); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters