-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: exceptions support null message
- Loading branch information
1 parent
5286c75
commit 31f101b
Showing
5 changed files
with
66 additions
and
6 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,59 @@ | ||
// import crypto from 'crypto'; | ||
// import os from 'os'; | ||
|
||
// const blockSize = 4; | ||
// const base = 36; | ||
// const discreteValues = Math.pow(base, blockSize); | ||
// const limit = Math.pow(2, 32) - 1; | ||
|
||
// const pad = (num: number | string, size: number) => { | ||
// const s = '000000000' + num; | ||
// return s.substring(s.length - size); | ||
// }; | ||
|
||
// const padSize = 2; | ||
// const hostname = os.hostname(); | ||
// const pid = pad(process.pid.toString(36), padSize); | ||
// const hostId = pad( | ||
// hostname | ||
// .split('') | ||
// .reduce((prev, char) => { | ||
// return Number(prev) + char.charCodeAt(0); | ||
// }, Number(hostname.length) + 36) | ||
// .toString(36), | ||
// padSize, | ||
// ); | ||
// const fingerprint = () => { | ||
// return pid + hostId; | ||
// }; | ||
|
||
// let c = 0; | ||
// const safeCounter = () => { | ||
// c = c < discreteValues ? c : 0; | ||
// c++; | ||
// return c - 1; | ||
// }; | ||
|
||
// const randomBlock = () => { | ||
// const ramdom = Math.abs(crypto.randomBytes(4).readInt32BE() / limit); | ||
// return pad(((ramdom * discreteValues) << 0).toString(base), blockSize); | ||
// }; | ||
|
||
// export const HelperCuid = (date: Date) => { | ||
// // hard-coded allows for sequential access | ||
// const letter = 'c'; | ||
|
||
// // warning: this exposes the exact date and time. | ||
// const timestamp = date.getTime().toString(base); | ||
|
||
// // Prevent same-machine collisions. | ||
// const counter = pad(safeCounter().toString(base), blockSize); | ||
|
||
// // reduce different-machine collisions | ||
// const print = fingerprint(); | ||
|
||
// // Grab some more chars from Math.random() | ||
// const random = randomBlock() + randomBlock(); | ||
|
||
// return letter + timestamp + counter + print + random; | ||
// }; |
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,7 +1,7 @@ | ||
import { BaseException } from './base'; | ||
|
||
export class UnauthorizedException extends BaseException { | ||
public constructor(messages: unknown, code = 'UnauthorizedException') { | ||
public constructor(messages?: unknown, code = 'UnauthorizedException') { | ||
super(401, messages, code); | ||
} | ||
} |
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,13 +1,13 @@ | ||
import { BaseException } from './base'; | ||
|
||
export class ForbiddenException extends BaseException { | ||
public constructor(messages: unknown, code = 'ForbiddenException') { | ||
public constructor(messages?: unknown, code = 'ForbiddenException') { | ||
super(403, messages, code); | ||
} | ||
} | ||
|
||
export class NeedVipException extends BaseException { | ||
public constructor(messages: unknown, code = 'NeedVip') { | ||
public constructor(messages?: unknown, code = 'NeedVip') { | ||
super(403, messages, code); | ||
} | ||
} |
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,7 +1,7 @@ | ||
import { BaseException } from './base'; | ||
|
||
export class NotFoundException extends BaseException { | ||
public constructor(messages: unknown, code = 'NotFoundException') { | ||
public constructor(messages?: unknown, code = 'NotFoundException') { | ||
super(404, messages, code); | ||
} | ||
} |
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