Leosac
0.8.0
Open Source Access Control
ModelException.cpp
Go to the documentation of this file.
1
/*
2
Copyright (C) 2014-2016 Leosac
3
4
This file is part of Leosac.
5
6
Leosac is free software: you can redistribute it and/or modify
7
it under the terms of the GNU Affero General Public License as published by
8
the Free Software Foundation, either version 3 of the License, or
9
(at your option) any later version.
10
11
Leosac is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU Affero General Public License for more details.
15
16
You should have received a copy of the GNU Affero General Public License
17
along with this program. If not, see <http://www.gnu.org/licenses/>.
18
*/
19
20
#include "
exception/ModelException.hpp
"
21
#include "
tools/log.hpp
"
22
23
ModelException::ModelException
(
const
std::string &source_pointer,
24
const
std::string &msg)
25
:
LEOSACException
(
"ModelException."
)
26
{
27
ModelError
e;
28
e.
source_pointer
= source_pointer;
29
e.
message
= msg;
30
errors_
.push_back(e);
31
32
message_
=
BUILD_STR
(
"ModelException: "
<<
json_errors
().dump(4));
33
}
34
35
ModelException::ModelException
(
36
const
std::initializer_list<ModelException::ModelError> &errors)
37
:
LEOSACException
(
"ModelException."
)
38
, errors_(errors)
39
{
40
message_
=
BUILD_STR
(
"ModelException: "
<<
json_errors
().dump(4));
41
}
42
43
ModelException::json
ModelException::json_errors
()
const
44
{
45
json
json_errors
= json::array();
46
for
(
const
auto
&error :
errors_
)
47
{
48
json
json_error;
49
json_error[
"detail"
] = error.message;
50
json_error[
"source"
][
"pointer"
] = error.source_pointer;
51
json_errors
.push_back(json_error);
52
}
53
54
return
json_errors
;
55
}
56
57
const
std::vector<ModelException::ModelError>
ModelException::errors
()
const
58
{
59
return
errors_
;
60
}
BUILD_STR
#define BUILD_STR(param)
Internal macro.
Definition:
log.hpp:63
ModelException::errors
const std::vector< ModelError > errors() const
Access the vector of errors.
Definition:
ModelException.cpp:57
LEOSACException::message_
std::string message_
Definition:
leosacexception.hpp:67
ModelException::ModelError::message
std::string message
The error message.
Definition:
ModelException.hpp:57
ModelException::ModelException
ModelException(const std::string &source_pointer, const std::string &msg)
This is an helper constructor that will instanciate a ModelError object from the 2 parameters.
Definition:
ModelException.cpp:23
LEOSACException
A base class for Leosac specific exception.
Definition:
leosacexception.hpp:40
ModelException::json_errors
json json_errors() const
Format the ModelError object(s).
Definition:
ModelException.cpp:43
ModelException.hpp
ModelException::ModelError::source_pointer
std::string source_pointer
The "path" to the source of the error.
Definition:
ModelException.hpp:52
ModelException::errors_
std::vector< ModelError > errors_
Definition:
ModelException.hpp:84
ModelException::json
nlohmann::json json
Definition:
ModelException.hpp:36
log.hpp
ModelException::ModelError
Describes a model error.
Definition:
ModelException.hpp:45
src
exception
ModelException.cpp
Generated on Tue Mar 22 2022 10:48:22 for Leosac by
1.8.17