Coverage for pygeoapi/error.py: 87%
13 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 08:15 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 08:15 +0000
1# =================================================================
2#
3# Authors: Bernhard Mallinger <bernhard.mallinger@eox.at>
4#
5# Copyright (c) 2024 Bernhard Mallinger
6#
7# Permission is hereby granted, free of charge, to any person
8# obtaining a copy of this software and associated documentation
9# files (the "Software"), to deal in the Software without
10# restriction, including without limitation the rights to use,
11# copy, modify, merge, publish, distribute, sublicense, and/or sell
12# copies of the Software, and to permit persons to whom the
13# Software is furnished to do so, subject to the following
14# conditions:
15#
16# The above copyright notice and this permission notice shall be
17# included in all copies or substantial portions of the Software.
18#
19# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
21# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26# OTHER DEALINGS IN THE SOFTWARE.
27#
28# =================================================================
31from http import HTTPStatus
34class GenericError(Exception):
35 """Exception class where error codes and messages
36 can be defined in custom error subclasses, so custom
37 providers and processes can raise appropriate errors.
38 """
40 ogc_exception_code = 'NoApplicableCode'
41 http_status_code = HTTPStatus.INTERNAL_SERVER_ERROR
42 default_msg = 'Unknown error'
44 def __init__(self, msg=None, *args, user_msg=None) -> None:
45 # if only a user_msg is provided, use it as msg
46 if user_msg and not msg: 46 ↛ 47line 46 didn't jump to line 47 because the condition on line 46 was never true
47 msg = user_msg
48 super().__init__(msg, *args)
49 self.user_msg = user_msg
51 @property
52 def message(self):
53 return self.user_msg if self.user_msg else self.default_msg