aboutsummaryrefslogtreecommitdiffstats
path: root/messagebus/src/vespa/messagebus/error.cpp
blob: f34bbb4883fe1e9b196ba1374d4bdfc144b391d7 (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
32
33
34
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "error.h"
#include "errorcode.h"
#include <vespa/vespalib/util/stringfmt.h>

using vespalib::make_string_short::fmt;

namespace mbus {

Error::Error()
    : _code(ErrorCode::NONE),
      _msg(),
      _service()
{ }

Error::~Error() = default;

Error::Error(uint32_t c, vespalib::stringref m, vespalib::stringref s)
    : _code(c),
      _msg(m),
      _service(s)
{ }

string
Error::toString() const
{
    string name(ErrorCode::getName(_code));
    if (name.empty()) {
        name = fmt("%u", _code);
    }
    return fmt("[%s @ %s]: %s", name.c_str(), _service.empty() ? "localhost" : _service.c_str(), _msg.c_str());
}

} // namespace mbus