Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
H
HELpy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hive
HELpy
Commits
41cab498
Commit
41cab498
authored
2 months ago
by
Krzysztof Mochocki
Browse files
Options
Downloads
Patches
Plain Diff
Add logging of CommunicationError to handles
parent
cde377e9
No related branches found
No related tags found
1 merge request
!73
Clive integration related fixes
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
helpy/helpy/_handles/abc/handle.py
+7
-2
7 additions, 2 deletions
helpy/helpy/_handles/abc/handle.py
helpy/helpy/_interfaces/error_logger.py
+39
-0
39 additions, 0 deletions
helpy/helpy/_interfaces/error_logger.py
with
46 additions
and
2 deletions
helpy/helpy/_handles/abc/handle.py
+
7
−
2
View file @
41cab498
...
...
@@ -12,6 +12,7 @@ from helpy._handles.settings import Settings
from
helpy._interfaces.context
import
SelfContextAsync
,
SelfContextSync
from
helpy._interfaces.settings_holder
import
UniqueSettingsHolder
from
helpy._interfaces.stopwatch
import
Stopwatch
from
helpy.exceptions
import
CommunicationError
from
schemas.jsonrpc
import
ExpectResultT
,
JSONRPCResult
,
get_response_model
if
TYPE_CHECKING
:
...
...
@@ -143,9 +144,11 @@ class AbstractAsyncHandle(AbstractHandle[ApiT], SelfContextAsync, ABC):
self
,
*
,
endpoint
:
str
,
params
:
str
,
expected_type
:
type
[
ExpectResultT
]
)
->
JSONRPCResult
[
ExpectResultT
]:
"""
Sends data asynchronously to handled service basing on jsonrpc.
"""
from
helpy._interfaces.error_logger
import
ErrorLogger
request
=
build_json_rpc_call
(
method
=
endpoint
,
params
=
params
)
self
.
_log_request
(
request
)
with
Stopwatch
()
as
record
:
with
Stopwatch
()
as
record
,
ErrorLogger
(
self
.
logger
,
CommunicationError
)
:
response
=
await
self
.
_overseer
.
async_send
(
self
.
http_endpoint
,
data
=
request
)
self
.
_log_response
(
record
.
seconds_delta
,
response
)
return
self
.
_response_handle
(
response
=
response
,
expected_type
=
expected_type
)
...
...
@@ -169,9 +172,11 @@ class AbstractSyncHandle(AbstractHandle[ApiT], SelfContextSync, ABC):
def
_send
(
self
,
*
,
endpoint
:
str
,
params
:
str
,
expected_type
:
type
[
ExpectResultT
])
->
JSONRPCResult
[
ExpectResultT
]:
"""
Sends data synchronously to handled service basing on jsonrpc.
"""
from
helpy._interfaces.error_logger
import
ErrorLogger
request
=
build_json_rpc_call
(
method
=
endpoint
,
params
=
params
)
self
.
_log_request
(
request
)
with
Stopwatch
()
as
record
:
with
Stopwatch
()
as
record
,
ErrorLogger
(
self
.
logger
,
CommunicationError
)
:
response
=
self
.
_overseer
.
send
(
self
.
http_endpoint
,
data
=
request
)
self
.
_log_response
(
record
.
seconds_delta
,
response
)
return
self
.
_response_handle
(
response
=
response
,
expected_type
=
expected_type
)
...
...
This diff is collapsed.
Click to expand it.
helpy/helpy/_interfaces/error_logger.py
0 → 100644
+
39
−
0
View file @
41cab498
from
__future__
import
annotations
from
typing
import
TYPE_CHECKING
from
loguru
import
logger
as
loguru_logger
from
helpy
import
ContextSync
if
TYPE_CHECKING
:
from
types
import
TracebackType
from
loguru
import
Logger
class
ErrorLogger
(
ContextSync
[
None
]):
def
__init__
(
self
,
logger
:
Logger
|
None
=
None
,
*
exceptions
:
type
[
Exception
])
->
None
:
super
().
__init__
()
self
.
__logger
=
logger
or
loguru_logger
self
.
__exception_whitelist
=
list
(
exceptions
)
def
_finally
(
self
)
->
None
:
return
None
def
_enter
(
self
)
->
None
:
return
None
def
_handle_exception
(
self
,
exception
:
BaseException
,
tb
:
TracebackType
|
None
)
->
bool
:
if
len
(
self
.
__exception_whitelist
)
>
0
:
for
whitelisted
in
self
.
__exception_whitelist
:
if
isinstance
(
exception
,
whitelisted
):
self
.
__log_exception
(
exception
)
break
return
super
().
_handle_exception
(
exception
,
tb
)
self
.
__log_exception
(
exception
)
return
super
().
_handle_exception
(
exception
,
tb
)
def
__log_exception
(
self
,
exception
:
BaseException
)
->
None
:
self
.
__logger
.
info
(
f
"
Exception occurred [
{
type
(
exception
)
}
]:
{
exception
}
"
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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