Skip to content

Commit 6e08df8

Browse files
committed
feat: implement custom exceptions for factory drive module
1 parent e768692 commit 6e08df8

30 files changed

+1665
-813
lines changed

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
"start:debug:webstorm": "node $NODE_DEBUG_OPTION -r ts-node/register -r tsconfig-paths/register src/main.ts"
4747
},
4848
"dependencies": {
49+
"@aws-sdk/client-s3": ">=3.600.0",
50+
"@aws-sdk/s3-request-presigner": "^3.600.0",
4951
"@nestjs-modules/ioredis": "^2.0.2",
5052
"@nestjs-modules/mailer": "^2.0.2",
5153
"@nestjs/axios": "^4.0.1",
@@ -60,8 +62,6 @@
6062
"@nestjs/platform-express": "^10.4.8",
6163
"@nestjs/schedule": "^6.0.0",
6264
"@nestjs/swagger": "^8.0.7",
63-
"@the-software-compagny/nestjs_module_factorydrive": "^1.1.5",
64-
"@the-software-compagny/nestjs_module_factorydrive-s3": "^1.0.1",
6565
"ajv": "^8.16.0",
6666
"ajv-errors": "^3.0.0",
6767
"ajv-formats": "^3.0.1",
@@ -75,6 +75,7 @@
7575
"cookie-parser": "^1.4.6",
7676
"dayjs": "^1.11.18",
7777
"fast-password-entropy": "^1.1.1",
78+
"fs-extra": "^11.3.2",
7879
"glob": "^11.0.0",
7980
"handlebars": "^4.7.8",
8081
"helmet": "^7.1.0",
@@ -89,6 +90,7 @@
8990
"nest-commander": "^3.13.0",
9091
"nest-winston": "^1.10.0",
9192
"nestjs-request-context": "^3.0.0",
93+
"node-exceptions": "^4.0.1",
9294
"nodemailer": "^6.9.16",
9395
"ora": "^8.1.0",
9496
"passport": "^0.7.0",
@@ -173,4 +175,4 @@
173175
"downloadUrl": "https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-debian10-5.0.22.tgz"
174176
}
175177
}
176-
}
178+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { RuntimeException } from 'node-exceptions'
2+
3+
export class AuthorizationRequiredException extends RuntimeException {
4+
public raw: Error
5+
6+
public constructor(err: Error, path: string) {
7+
super(`Unauthorized to access file ${path}\n${err.message}`, 500, 'E_AUTHORIZATION_REQUIRED')
8+
this.raw = err
9+
}
10+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { RuntimeException } from 'node-exceptions'
2+
3+
export class DriverNotSupportedException extends RuntimeException {
4+
public driver!: string
5+
6+
public static driver(name: string): DriverNotSupportedException {
7+
const exception = new this(`Driver ${name} is not supported`, 400)
8+
exception.driver = name
9+
return exception
10+
}
11+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { RuntimeException } from 'node-exceptions'
2+
3+
export class FileNotFoundException extends RuntimeException {
4+
public raw: Error
5+
6+
public constructor(err: Error, path: string) {
7+
super(`The file ${path} doesn't exist\n${err.message}`, 500, 'E_FILE_NOT_FOUND')
8+
this.raw = err
9+
}
10+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export * from './authorization-required.exception'
2+
export * from './driver-not-supported.exception'
3+
export * from './file-not-found.exception'
4+
export * from './invalid-config.exception'
5+
export * from './method-not-supported.exception'
6+
export * from './no-such-bucket.exception'
7+
export * from './permission-missing.exception'
8+
export * from './unknown.exception'
9+
export * from './wrong-key-path.exception'
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { RuntimeException } from 'node-exceptions'
2+
3+
export class InvalidConfigException extends RuntimeException {
4+
public static missingDiskName(): InvalidConfigException {
5+
return new this('Make sure to define a default disk name inside config file', 500, 'E_INVALID_CONFIG')
6+
}
7+
8+
public static missingDiskConfig(name: string): InvalidConfigException {
9+
return new this(`Make sure to define config for ${name} disk`, 500, 'E_INVALID_CONFIG')
10+
}
11+
12+
public static missingDiskDriver(name: string): InvalidConfigException {
13+
return new this(`Make sure to define driver for ${name} disk`, 500, 'E_INVALID_CONFIG')
14+
}
15+
16+
public static duplicateDiskName(name: string): InvalidConfigException {
17+
return new this(`A disk named ${name} is already defined`, 500, 'E_INVALID_CONFIG')
18+
}
19+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { RuntimeException } from 'node-exceptions'
2+
3+
export class MethodNotSupportedException extends RuntimeException {
4+
public constructor(name: string, driver: string) {
5+
super(`Method ${name} is not supported for the driver ${driver}`, 500, 'E_METHOD_NOT_SUPPORTED')
6+
}
7+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { RuntimeException } from 'node-exceptions'
2+
3+
export class NoSuchBucketException extends RuntimeException {
4+
public raw: Error
5+
6+
public constructor(err: Error, bucket: string) {
7+
super(`The bucket ${bucket} doesn't exist\n${err.message}`, 500, 'E_NO_SUCH_BUCKET')
8+
this.raw = err
9+
}
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { RuntimeException } from 'node-exceptions'
2+
3+
export class PermissionMissingException extends RuntimeException {
4+
public raw: Error
5+
6+
public constructor(err: Error, path: string) {
7+
super(`Missing permission for file ${path}\n${err.message}`, 500, 'E_PERMISSION_MISSING')
8+
this.raw = err
9+
}
10+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { RuntimeException } from 'node-exceptions'
2+
3+
export class UnknownException extends RuntimeException {
4+
public raw: Error
5+
6+
public constructor(err: Error, errorCode: string, path: string) {
7+
super(
8+
`An unknown error happened with the file ${path}.
9+
Error code: ${errorCode}
10+
Original stack:
11+
${err.stack}`,
12+
500,
13+
'E_UNKNOWN',
14+
)
15+
this.raw = err
16+
}
17+
}

0 commit comments

Comments
 (0)