Skip to content

Pipeline ​

Class

A pipeline represents the call stack for a service. With a pipeline, we can register a series of hooks for a service. The pipeline is responsible for running hooks in the correct order and handling/propagating errors correctly.

Use the before and after methods to register hooks.

constructor ​

service ​

after ​

typescript
public after(method: Parameter, hook: Parameter, config: Parameter): Promise<any>
public after(method: Parameter, hook: Parameter, config: Parameter): Promise<any>

before ​

typescript
public before(method: Parameter, hook: Parameter, config: Parameter): Promise<any>
public before(method: Parameter, hook: Parameter, config: Parameter): Promise<any>

hook ​

typescript
public hook(when: Parameter, method: Parameter, hook: Parameter, config: Parameter): Promise<any>
public hook(when: Parameter, method: Parameter, hook: Parameter, config: Parameter): Promise<any>

run ​

typescript
public run(ctx: Parameter): Promise<any>
public run(ctx: Parameter): Promise<any>

Passes the context through the before hooks registered on the app, followed by hooks registered on the service. After all before-hooks are called, the context is passed to the service. The result from the service is then passed through all after hooks.

If a before-hook happens to set the result of the context to a non-null result, the pipeline does not call the subsequent before-hooks and also skips the service but runs all after-hooks with the current context.

When there's an error/exception, the pipeline tries to handle it cleanly and return a context with the respective status code and result. In this case, the after hooks are not called; rather the error hooks registered on the app are called.

handleError ​

typescript
public handleError(err: Parameter, ctx: Parameter, clean: Parameter): Promise<any>
public handleError(err: Parameter, ctx: Parameter, clean: Parameter): Promise<any>

stubHooks ​

typescript
public stubHooks(): Promise<any>
public stubHooks(): Promise<any>

translateError ​

typescript
public translateError(err: Parameter): Promise<any>
public translateError(err: Parameter): Promise<any>