-
Notifications
You must be signed in to change notification settings - Fork 1
/
flights_err.cpp
57 lines (47 loc) · 1.65 KB
/
flights_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
54
55
56
57
#include "flights_err.h"
namespace flightservice {
namespace { // anonymous namespace for category definition
struct FlightsErrCategory : public std::error_category {
const char* name() const noexcept override;
std::string message(int ev) const override;
};
const char* FlightsErrCategory::name() const noexcept
{
return "FlightsErr";
}
std::string FlightsErrCategory::message(int ev) const
{
switch (static_cast<FlightsErr>(ev)) {
case FlightsErr::NonexistentLocations:
return "nonexistent airport name in request";
case FlightsErr::DatesInThePast:
return "request for a date from the past";
case FlightsErr::InvertedDates:
return "requested flight return date before departure date";
case FlightsErr::NoFlightsFound:
return "no flight combination found";
case FlightsErr::ProtocolViolation:
return "received malformed request";
case FlightsErr::ConnectionError:
return "could not connect to server";
case FlightsErr::ResourceError:
return "insufficient resources";
case FlightsErr::Timeout:
return "processing timed out";
default:
break;
}
return "(unrecognized error)";
}
// global object for unify this category
const FlightsErrCategory the_flights_err_category {};
}
const std::error_category& get_flights_err_category() noexcept
{
return the_flights_err_category;
}
std::error_code make_error_code(flightservice::FlightsErr e) noexcept
{
return { static_cast<int>(e), the_flights_err_category };
}
}