Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
api
Manage
Activity
Members
Labels
Plan
Issues
5
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
retribute.me
api
Commits
a82bca0b
Verified
Commit
a82bca0b
authored
5 years ago
by
Eliot Berriot
Browse files
Options
Downloads
Patches
Plain Diff
Better error handling
parent
1e5eab9a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
retribute_api/search/consumers.py
+13
-3
13 additions, 3 deletions
retribute_api/search/consumers.py
with
13 additions
and
3 deletions
retribute_api/search/consumers.py
+
13
−
3
View file @
a82bca0b
...
...
@@ -9,6 +9,9 @@ from . import sources
from
.
import
serializers
aiohttp_timeout
=
aiohttp
.
ClientTimeout
(
total
=
10
)
async
def
json_response
(
self
,
status
,
content
):
await
self
.
send_response
(
status
,
...
...
@@ -40,11 +43,14 @@ class SearchSingleConsumer(AsyncHttpConsumer):
except
KeyError
:
await
json_response
(
self
,
400
,
{
"
detail
"
:
"
Invalid lookup
"
})
try
:
async
with
aiohttp
.
client
.
ClientSession
(
timeout
=
5
)
as
session
:
async
with
aiohttp
.
client
.
ClientSession
(
timeout
=
aiohttp_timeout
)
as
session
:
data
=
await
source
.
get
(
lookup
,
session
)
profile
=
sources
.
result_to_retribute_profile
(
lookup_type
,
lookup
,
data
)
except
(
exceptions
.
SearchError
,
aiohttp
.
ClientError
)
as
e
:
await
json_response
(
self
,
400
,
{
"
detail
"
:
e
.
message
})
except
Exception
:
await
json_response
(
self
,
500
,
{})
raise
await
json_response
(
self
,
200
,
profile
)
...
...
@@ -77,7 +83,7 @@ class SearchMultipleConsumer(AsyncHttpConsumer):
lookups
=
serializer
.
validated_data
[
"
lookups
"
]
results
=
{}
tasks
=
[]
async
with
aiohttp
.
client
.
ClientSession
(
timeout
=
15
)
as
session
:
async
with
aiohttp
.
client
.
ClientSession
(
timeout
=
aiohttp_timeout
)
as
session
:
for
lookup_type
,
lookup
in
lookups
:
try
:
source
=
sources
.
registry
.
_data
[
lookup_type
]
...
...
@@ -94,5 +100,9 @@ class SearchMultipleConsumer(AsyncHttpConsumer):
results
=
results
,
)
)
await
asyncio
.
gather
(
*
tasks
)
try
:
await
asyncio
.
gather
(
*
tasks
)
except
Exception
as
e
:
await
json_response
(
self
,
500
,
{})
raise
await
json_response
(
self
,
200
,
results
)
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