ApiError
ApiError class is designed to send errors to the HTTP client easily. You can use it in any hooks.
You can check the following example;
ts
import { IHookParameter, ApiError, StatusCodes } from "axe-api";
export default async (parameters: IHookParameter) => {
throw new ApiError(
"This is not an acceptable request!",
StatusCodes.BAD_REQUEST
);
};
By this example, you can get the following error in the HTTP response body;
bash
curl \
-H "Content-Type: application/json" \
-X POST http://localhost:3000/api/v1/users
json
{
"error": "This is not an acceptable request!"
}