-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(errors): update how errors are created
- Loading branch information
Showing
7 changed files
with
27 additions
and
36 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
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
4 changes: 2 additions & 2 deletions
4
src/lib/errors/Imperial/DocumentNotFound.ts → src/lib/errors/Imperial/NotFound.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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import { ImperialError } from "../ImperialError"; | ||
|
||
export class DocumentNotFound extends ImperialError { | ||
export class NotFound extends ImperialError { | ||
constructor(...args: ConstructorParameters<typeof ImperialError>) { | ||
super(...args); | ||
|
||
this.message = "We could not find that Document!"; | ||
this.message = "We could not find that Document or User"; | ||
this.status = 404; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,18 +1,21 @@ | ||
export const NO_TEXT = "No `text` was provided!"; | ||
|
||
export const TEXT_WRONG_TYPE = "Parameter `text` must be a string!"; | ||
|
||
export const NO_TOKEN = "This method requires a token to be set in the constructor!"; | ||
|
||
export const NO_ID = "No `id` was provided!"; | ||
|
||
export const ID_WRONG_TYPE = "Parameter `id` must be a string or an URL!"; | ||
|
||
export const PASSWORD_WRONG_TYPE = "Parameter `password` must be a string!"; | ||
|
||
export const OPTIONS_WRONG_TYPE = "Parameter `options` must be an Object!"; | ||
|
||
export const SCHEMA_FAILED_VALIDATION = (key: string, message: string, required: boolean = false): string => | ||
`Property "${key}" ${required ? "is required and " : ""}must be ${message}`; | ||
|
||
export const SCHEMA_INVALID_KEY = (key: string): string => `They key ${key} is not on the schema`; | ||
const Messages = { | ||
NO_TEXT: "No `text` was provided", | ||
TEXT_WRONG_TYPE: "Parameter `text` must be a string", | ||
NO_TOKEN: "This method requires a token to be set in the constructor", | ||
NO_ID: "No `id` was provided", | ||
NO_USERNAME: "No `username` was provided", | ||
ID_WRONG_TYPE: "Parameter `id` must be a string or an URL", | ||
USERNAME_WRONG_TYPE: "Parameter `username` must be a string", | ||
PASSWORD_WRONG_TYPE: "Parameter `password` must be a string", | ||
OPTIONS_WRONG_TYPE: "Parameter `options` must be an Object", | ||
SCHEMA_FAILED_VALIDATION(key: string, message: string, required: boolean = false): string { | ||
return `Property "${key}" ${required ? "is required and " : ""}must be ${message}`; | ||
}, | ||
SCHEMA_INVALID_KEY(key: string): string { | ||
return `They key "${key}" is not on the schema`; | ||
}, | ||
} as const; | ||
|
||
type MessageKeys = keyof typeof Messages; | ||
|
||
export const ErrorMessage = <T extends MessageKeys>(key: T) => Messages[key] as typeof Messages[T]; |
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,6 +1,5 @@ | ||
export { DocumentNotFound } from "./Imperial/DocumentNotFound"; | ||
export { NotFound } from "./Imperial/NotFound"; | ||
export { ImperialError } from "./ImperialError"; | ||
export { Aborted } from "./HTTPErrors/Aborted"; | ||
export { FailedToFetch } from "./HTTPErrors/FailedToFetch"; | ||
export { NotAllowed } from "./Imperial/EditNotAllowed"; | ||
export { WrongPassword } from "./Imperial/WrongPassword"; | ||
export { NotAllowed } from "./Imperial/NotAllowed"; |