-
Notifications
You must be signed in to change notification settings - Fork 1
/
seats_err.cpp
53 lines (43 loc) · 1.39 KB
/
seats_err.cpp
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "seats_err.h"
namespace flightservice {
namespace { // anonymous namespace for category definition
struct SeatsErrCategory : public std::error_category {
const char* name() const noexcept override;
std::string message(int ev) const override;
};
const char* SeatsErrCategory::name() const noexcept
{
return "SeatsErr";
}
std::string SeatsErrCategory::message(int ev) const
{
switch (static_cast<SeatsErr>(ev)) {
case SeatsErr::InvalidRequest:
return "invalid request";
case SeatsErr::CouldNotConnect:
return "could not connect to server";
case SeatsErr::InternalError:
return "service run short of resources";
case SeatsErr::NoResponse:
return "did not respond in time";
case SeatsErr::NonexistentClass:
return "requested class does not exist";
case SeatsErr::NoSeatAvailable:
return "all seats booked";
default:
break;
}
return "(unrecognized error)";
}
// global object for unify this category
const SeatsErrCategory the_seats_err_category {};
}
const std::error_category& get_seats_err_category() noexcept
{
return the_seats_err_category;
}
std::error_code make_error_code(flightservice::SeatsErr e) noexcept
{
return { static_cast<int>(e), the_seats_err_category };
}
}