Skip to content

ServiceExt::short_circuit #647

@BrynCooke

Description

@BrynCooke

Currently the filter layer allows processing to be halted, but an error must be returned because Result is used to indicate continued processing.
It'd be good to be able to have the same functionality but use a dedicated enum to indicate continued processing.

Example uses:

  • Caching - Return a response immediately (either Ok or Err)
  • Validation - Abort processing, but OK response object should be returned which contains error code and message. BoxError is not suitable because structured errors are lost.

Something like:

builder.short_circuit(|request| {
    ShortCircuit::Continue(request) //Continue processing using the supplied request
    ShortCircuit::Abort(Ok(response)) //Abort processing returning OK
    ShortCircuit::Abort(Err(error)) //Abort processing returning Err
});

Like filter, it would be good to have an async version. I'd be willing to create a PR for this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions