Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
indicators-parser-saas
backend
Commits
2d76b564
Verified
Commit
2d76b564
authored
2 years ago
by
Власов Иван Юрьевич
Browse files
Options
Download
Patches
Plain Diff
Created some errors and ErrorResponse
parent
e30aa321
master
No related merge requests found
Pipeline
#98276
passed with stage
in 1 minute and 9 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
responses/errors.py
+26
-0
responses/errors.py
responses/responses.py
+23
-0
responses/responses.py
with
49 additions
and
0 deletions
+49
-0
responses/errors.py
0 → 100644
+
26
−
0
View file @
2d76b564
from
responses.responses
import
BadResponse
class
ApiError
(
Exception
):
""" Base API error """
code
:
int
description
:
str
http_code
:
int
=
500
def
as_response
(
self
):
""" Error as a response """
return
BadResponse
(
self
.
code
,
self
.
description
,
self
.
http_code
)
class
GithubBadCodeError
(
ApiError
):
""" GitHub callback code error """
code
=
101
description
=
"Github authorization code is incorrect"
http_code
=
412
class
GithubError
(
ApiError
):
""" GitHub internal bad response """
code
=
102
description
=
"Github authorization error"
http_code
=
500
This diff is collapsed.
Click to expand it.
responses/responses.py
+
23
−
0
View file @
2d76b564
...
...
@@ -25,6 +25,29 @@ class ResponseModel(BaseModel):
class
OkResponse
(
JSONResponse
):
""" OK Response, might use pydantic object or just dict """
def
render
(
self
,
content
:
Any
)
->
bytes
:
as_json
=
ResponseModel
(
data
=
content
).
dict
()
return
dumps
(
as_json
,
option
=
orjson
.
OPT_OMIT_MICROSECONDS
)
class
BadResponse
(
JSONResponse
):
""" Error response, might be returned by exception """
def
__init__
(
self
,
error_code
:
int
,
description
:
str
,
status_code
:
int
):
"""
Constructor
Parameters:
error_code: int Error code of exception
description: str User-readable description of error
status_code: int Http Status code
"""
content
=
{
"error_code"
:
error_code
,
"description"
:
description
}
super
().
__init__
(
content
,
status_code
=
status_code
)
def
render
(
self
,
content
:
Any
)
->
bytes
:
as_json
=
ResponseModel
(
data
=
content
,
ok
=
False
).
dict
()
return
dumps
(
as_json
)
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets