Commands
Handling Errors
With Seyfert, you can handle errors in an organized way and treat them differently depending on the type of error.
Error when executing a command
This is the most common error and occurs when an error is thrown in the run method.
import { , type } from "seyfert";
export class extends {
async (: ) {
throw new ("Error, ehm, lol player detected");
}
// : This responds with the previous error message: "Error, ehm, lol player detected"
async (: , : unknown) {
...();
await .({
: instanceof ? . : `Error: ${}`
});
}
}Error when validating options
This error is thrown when an option fails in the value method.
const = {
: ({
: 'how to be a gamer',
(, : <URL>, ) {
if ((.)) return (new (.));
// This will trigger the onOptionsError method
('expected a valid URL');
},
})
};
@()
export class extends {
async (
: ,
:
) {
// : url: expected a valid URL
await .({
: .()
.(() => [1].)
.(() => `${[0]}: ${[1].}`)
.("\n")
});
}
}Stop a middleware with an error
When a middleware returns a stop, Seyfert generates this error and stops the progress of the command being handled.
import { } from "seyfert";
export default <void>(({ , , , }) => {
if (!.(..)) {
return ("User is not a developer");
}
();
});import { , , type } from "seyfert";
@(["OnlyDev"])
export class extends {
async (: , : string) {
await .({
// : User is not a developer
:
});
}
}Although Seyfert provides a way to handle errors, you can do it in the way that best suits your needs (we recommend the way we showed, lol).