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) self._add(date, item_id)
def get_cve_search(self): def get_cve_search(self):
response = requests.get(f'https://cvepremium.circl.lu/api/cve/{self.id}', timeout=10) try:
if response.status_code == 200: response = requests.get(f'https://cvepremium.circl.lu/api/cve/{self.id}', timeout=10)
json_response = response.json() if response.status_code == 200:
# 'summary' json_response = response.json()
# 'references' # 'summary'
# 'last-modified' # 'references'
# 'Published' # 'last-modified'
# 'Modified' # 'Published'
return json_response # 'Modified'
else: return json_response
return {'error': f'{response.status_code}'} else:
return {'error': f'{response.status_code}'}
except requests.exceptions.ConnectionError:
return {'error': f'Connection Error'}
# TODO ADD SEARCH FUNCTION # TODO ADD SEARCH FUNCTION

View file

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