fix: [cves] catch cve search errors

This commit is contained in:
Terrtia 2023-05-12 09:59:18 +02:00
parent f4d20533cc
commit 98cbaad1ad
No known key found for this signature in database
GPG key ID: 1E1B1F50D84613D0
2 changed files with 64 additions and 57 deletions

View file

@ -76,17 +76,21 @@ class Cve(AbstractDaterangeObject):
self._add(date, item_id)
def get_cve_search(self):
response = requests.get(f'https://cvepremium.circl.lu/api/cve/{self.id}', timeout=10)
if response.status_code == 200:
json_response = response.json()
# 'summary'
# 'references'
# 'last-modified'
# 'Published'
# 'Modified'
return json_response
else:
return {'error': f'{response.status_code}'}
try:
response = requests.get(f'https://cvepremium.circl.lu/api/cve/{self.id}', timeout=10)
if response.status_code == 200:
json_response = response.json()
# 'summary'
# 'references'
# 'last-modified'
# 'Published'
# 'Modified'
return json_response
else:
return {'error': f'{response.status_code}'}
except requests.exceptions.ConnectionError:
return {'error': f'Connection Error'}
# TODO ADD SEARCH FUNCTION

View file

@ -47,57 +47,60 @@
</div>
</li>
{% if dict_object["metadata_card"]["cve_search"] %}
<li class="list-group-item py-0">
<table class="table table-sm table-hover">
<tbody>
<tr>
<td><b>Summary</b></td>
<td>{{ dict_object["metadata_card"]["cve_search"].get("summary") }}</td>
</tr>
<tr>
<td><b>Published</b></td>
<td>{{ dict_object["metadata_card"]["cve_search"].get("Published") }}</td>
</tr>
<tr>
<td><b>Modified</b></td>
<td>{{ dict_object["metadata_card"]["cve_search"].get("Modified") }}</td>
</tr>
<tr>
<td><b>last-modified</b></td>
<td>{{ dict_object["metadata_card"]["cve_search"].get("last-modified") }}</td>
</tr>
</tbody>
</table>
</li>
{% if 'error' in dict_object["metadata_card"]["cve_search"] %}
<b class="text-danger my-2"><i class="fas fa-exclamation-triangle"></i> CVE Search Error: {{ dict_object["metadata_card"]["cve_search"]["error"] }}</b>
{% else %}
<li class="list-group-item py-0">
<table class="table table-sm table-hover">
<tbody>
<tr>
<td><b>Summary</b></td>
<td>{{ dict_object["metadata_card"]["cve_search"].get("summary") }}</td>
</tr>
<tr>
<td><b>Published</b></td>
<td>{{ dict_object["metadata_card"]["cve_search"].get("Published") }}</td>
</tr>
<tr>
<td><b>Modified</b></td>
<td>{{ dict_object["metadata_card"]["cve_search"].get("Modified") }}</td>
</tr>
<tr>
<td><b>last-modified</b></td>
<td>{{ dict_object["metadata_card"]["cve_search"].get("last-modified") }}</td>
</tr>
</tbody>
</table>
</li>
{% if dict_object["metadata_card"]["cve_search"].get("references") %}
<div id="accordion" class="mb-2">
<div class="card">
<div class="card-header bg-dark" id="headingRefs">
<h5 class="mb-0">
<button class="btn btn-link collapsed w-100" data-toggle="collapse" data-target="#collapseRefs" aria-expanded="false" aria-controls="collapseRefs">
<span class="row">
<div class="col-10 text-left">
References <span class="badge badge-primary badge-pill">{{ dict_object["metadata_card"]["cve_search"]["references"] | length }}</span>
</div>
<div class="col-2 text-right"><i class="fas fa-chevron-circle-down"></i></div>
</span>
</button>
</h5>
</div>
<div id="collapseRefs" class="collapse" aria-labelledby="headingRefs" data-parent="#accordion">
<div class="card-body">
<ul>
{% for ref in dict_object["metadata_card"]["cve_search"].get("references") %}
<li>{{ ref }}</li>
{% endfor %}
</ul>
{% if dict_object["metadata_card"]["cve_search"].get("references") %}
<div id="accordion" class="mb-2">
<div class="card">
<div class="card-header bg-dark" id="headingRefs">
<h5 class="mb-0">
<button class="btn btn-link collapsed w-100" data-toggle="collapse" data-target="#collapseRefs" aria-expanded="false" aria-controls="collapseRefs">
<span class="row">
<div class="col-10 text-left">
References <span class="badge badge-primary badge-pill">{{ dict_object["metadata_card"]["cve_search"]["references"] | length }}</span>
</div>
<div class="col-2 text-right"><i class="fas fa-chevron-circle-down"></i></div>
</span>
</button>
</h5>
</div>
<div id="collapseRefs" class="collapse" aria-labelledby="headingRefs" data-parent="#accordion">
<div class="card-body">
<ul>
{% for ref in dict_object["metadata_card"]["cve_search"].get("references") %}
<li>{{ ref }}</li>
{% endfor %}
</ul>
</div>
</div>
</div>
</div>
</div>
{% endif %}
{% endif %}
{% endif %}
<li class="list-group-item py-0">
<br>