New Fluxzy v2 just shipped. Electron is out, Tauri is in. gRPC ready, 3x smaller install. Learn more

rejectWithMessageAction Action

Block matching requests and return a custom status code, body, and content type so clients receive a meaningful explanation.

A blocked request is more useful when it tells the client what just happened. With rejectWithMessageAction you keep the safety of a server side block and combine it with a body the user, the browser, or the API client can actually parse and react to.

When to use this action

rejectWithMessageAction is the right choice when the client should not just be denied, but should also receive a clear explanation. You decide the status code, the body, and the content type.

Common reasons to use it:

  • Show a corporate policy page when a user reaches a blocked domain.
  • Return a structured JSON error payload to API clients so their error handlers behave normally.
  • Replace a third party endpoint with a stub that mimics a known failure response.

When you only need a status code without a body, rejectWithStatusCodeAction is lighter. For full control over headers as well, use mockedResponseAction.

Real world examples

Return a corporate policy HTML page

Serve a styled message when a browser user reaches a blocked hostname so they understand why the request was refused.

rules:
- filter:
    typeKind: HostFilter
    pattern: tracker.example.com
  actions:
  - typeKind: RejectWithMessageAction
    statusCode: 403
    contentType: text/html
    message: <html><body><h1>Blocked</h1><p>Tracking domains are blocked on this network. Contact IT for exceptions.</p></body></html>

Return a JSON error for an API client

API consumers expect machine readable errors. Provide a JSON body so their error handling code keeps working when the endpoint is blocked.

rules:
- filter:
    typeKind: HostFilter
    pattern: api.internal.example.com
  actions:
  - typeKind: RejectWithMessageAction
    statusCode: 503
    contentType: application/json
    message: '{"error":"service_unavailable","message":"This endpoint is intentionally disabled in the staging proxy."}'

Show a friendly text message for a deprecated endpoint

Useful when migrating consumers off a legacy path. The plain text body explains the migration without needing HTML rendering.

rules:
- filter:
    typeKind: PathFilter
    pattern: ^/v1/legacy
  actions:
  - typeKind: RejectWithMessageAction
    statusCode: 410
    contentType: text/plain
    message: This endpoint was removed on 2026-01-01. Please migrate to /v2/orders.

Reference

rejectWithMessageAction

Description

Block the request with a custom HTTP error response including a body message. Useful for providing detailed blocking reasons to end users. Supports text/plain, text/html, and application/json content types.

Evaluation scope

Evaluation scope defines the timing where this filter will be applied.

requestHeaderReceivedFromClient This scope occurs the moment fluxzy parsed the request header receiveid from client

YAML configuration name

rejectWithMessageAction

Settings

This action has no specific characteristic

Example of usage

The following examples apply this action to any exchanges

Block with a plain text message.

rules:
- filter:
    typeKind: AnyFilter
  actions:
  - typeKind: RejectWithMessageAction
    statusCode: 403
    message: Access to this site is blocked by corporate policy
    contentType: text/plain

Block with an HTML page.

rules:
- filter:
    typeKind: AnyFilter
  actions:
  - typeKind: RejectWithMessageAction
    statusCode: 403
    message: <html><body><h1>Blocked</h1><p>This site has been blocked for security reasons.</p></body></html>
    contentType: text/html

Block with a JSON response (for APIs).

rules:
- filter:
    typeKind: AnyFilter
  actions:
  - typeKind: RejectWithMessageAction
    statusCode: 403
    message: '{"error": "forbidden", "message": "This endpoint is blocked"}'
    contentType: application/json

.NET reference

View definition of RejectWithMessageAction for .NET integration.

See also

The following actions are related to this action:

Frequently asked questions

What content types are supported?

Any value is allowed in the contentType field, but the action is designed around text/plain, text/html, and application/json. Fluxzy sets the Content-Type header to whatever you provide.

Can the message body contain rule variables?

Yes, the same variable substitution that applies elsewhere in the rule pipeline applies to the message field. You can include exchange specific values when needed.

Does the upstream server receive the original request?

No. The action short circuits the exchange after parsing the client request, so the upstream service never sees the call.

How do I add custom response headers?

Combine this action with addResponseHeaderAction, or switch to mockedResponseAction if you need full control over the response.

Learn more about Fluxzy rules