fix: [app:requests] Catch if request failed

This commit is contained in:
Sami Mokaddem 2024-07-01 14:40:32 +02:00
parent a417e09b0f
commit 8ea636065c
6 changed files with 42 additions and 35 deletions

1
.gitignore vendored
View file

@ -12,7 +12,6 @@ lerna-debug.log*
node_modules
.DS_Store
dist
dist-ssr
coverage
*.local

File diff suppressed because one or more lines are too long

2
dist/index.html vendored
View file

@ -5,7 +5,7 @@
<link rel="icon" href="/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vite App</title>
<script type="module" crossorigin src="/assets/index-CrmZ3McV.js"></script>
<script type="module" crossorigin src="/assets/index-DNFQtfBp.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-CIUN73PR.css">
</head>
<body>

View file

@ -19,7 +19,10 @@ def get(url, data={}, api_key=misp_apikey):
"Content-Type": "application/json"
}
full_url = urljoin(misp_url, url)
response = requests.get(full_url, data=data, headers=headers, verify=not misp_skipssl)
try:
response = requests.get(full_url, data=data, headers=headers, verify=not misp_skipssl)
except requests.exceptions.ConnectionError:
return None
return response.json() if response.headers['content-type'].startswith('application/json') else response.text
@ -31,7 +34,10 @@ def post(url, data={}, api_key=misp_apikey):
"Content-Type": "application/json"
}
full_url = urljoin(misp_url, url)
response = requests.post(full_url, data=json.dumps(data), headers=headers, verify=not misp_skipssl)
try:
response = requests.post(full_url, data=json.dumps(data), headers=headers, verify=not misp_skipssl)
except requests.exceptions.ConnectionError:
return None
return response.json() if response.headers['content-type'].startswith('application/json') else response.text

View file

@ -157,4 +157,4 @@ if __name__ == "__main__":
eventlet.spawn_n(forward_zmq_to_socketio)
# Run the Socket.IO server
eventlet.wsgi.server(eventlet.listen(('0.0.0.0', 4000)), app)
eventlet.wsgi.server(eventlet.listen(('127.0.0.1', 4000)), app)

View file

@ -93,29 +93,31 @@
</span>
</h4>
<h4 class="font-semibold ml-1"><strong>MISP Settings:</strong></h4>
<div class="ml-3">
<div v-if="diagnosticLoading" class="flex justify-center">
<span class="loading loading-dots loading-lg"></span>
</div>
<div
v-for="(value, setting) in diagnostic['settings']"
:key="setting"
>
<div>
<label class="label cursor-pointer justify-start p-0 pt-1">
<input
type="checkbox"
:checked="value"
:value="setting"
:class="`checkbox ${value ? 'checkbox-success' : 'checkbox-danger'} [--fallback-bc:#cbd5e1]`"
disabled
/>
<span class="font-mono font-semibold text-base ml-3">{{ setting }}</span>
</label>
<template v-if="diagnosticLoading || isMISPOnline">
<h4 class="font-semibold ml-1"><strong>MISP Settings:</strong></h4>
<div class="ml-3">
<div v-if="diagnosticLoading" class="flex justify-center">
<span class="loading loading-dots loading-lg"></span>
</div>
<div
v-for="(value, setting) in diagnostic['settings']"
:key="setting"
>
<div>
<label class="label cursor-pointer justify-start p-0 pt-1">
<input
type="checkbox"
:checked="value"
:value="setting"
:class="`checkbox ${value ? 'checkbox-success' : 'checkbox-danger'} [--fallback-bc:#cbd5e1]`"
disabled
/>
<span class="font-mono font-semibold text-base ml-3">{{ setting }}</span>
</label>
</div>
</div>
</div>
</div>
</template>
</div>
</div>