Filters
Filters are the step that allow you to catch errors thrown by the main transport step and to transform the response before it is sent back to the client. In the context of AxiSpark.js, filters are used to handle errors and to modify the response data before it is returned to the client.
Filter example
filter.ts
@Filter({ transport: ExecutionTransport.Http, global: true })
export class MyFilter {
@Catch(CustomError, AnotherError)
public async catch(@Error() error: Error) {
...
}
@Catch(Error)
public async catchAll(@Error() error: Error) {
...
}
}
It's common to have multiple methods decorated with
@Catch()in a Filter class, each method will be executed in the order they are defined in the class only if the error thrown by the main transport step matches the error type specified in the@Catch()decorator. If no method matches the error type, the error will be propagated to the next filter in the chain or to the client if there are no more filters.