aboutsummaryrefslogtreecommitdiffstats
path: root/documentapi/src/vespa/documentapi/messagebus/policies/errorpolicy.h
blob: 3e25b545691f744c9b0bc0dd2dea8130bb373f03 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include <vespa/documentapi/common.h>
#include <vespa/messagebus/routing/iroutingpolicy.h>

namespace documentapi {

/**
 * This policy assigns an error supplied at constructor time to the routing context when {@link
 * #select(RoutingContext)} is invoked. This is useful for returning error states to the client instead of
 * those auto-generated by mbus when a routing policy can not be created.
 */
class ErrorPolicy : public mbus::IRoutingPolicy {
private:
    string _msg;

public:
    /**
     * Creates a new policy that will assign an {@link EmptyReply} with the given error to all routing
     * contexts that invoke {@link #select(RoutingContext)}.
     *
     * @param msg The message of the error to assign.
     */
    ErrorPolicy(const string &msg);
    void select(mbus::RoutingContext &context) override;
    void merge(mbus::RoutingContext &context) override;
};

}