How to throw errors from content sources?
Summary
This method can be used in PageBuilder Engine content sources to generate not found 404 and redirect 302 errors/status codes from a PageBuilder Engine content source.
Procedure
- Create an error in the content source. This can be a custom class or a regular error.
- Set a
statusCode. If it is a 3xx status code, you can provide a location to redirect to. - Use
throwto generate the error.
Examples:
Custom not found error
const NotFoundError = (message = 'Not Found') => { const err = new Error(message); err.statusCode = 404; return err;}Custom redirect error
const RedirectError = (message = 'Redirect', code = 302, location) => { const err = new Error(message); err.statusCode = code; err.location = location; return err;}