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 node_modules
.DS_Store .DS_Store
dist
dist-ssr dist-ssr
coverage coverage
*.local *.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"> <link rel="icon" href="/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vite App</title> <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"> <link rel="stylesheet" crossorigin href="/assets/index-CIUN73PR.css">
</head> </head>
<body> <body>

View file

@ -19,7 +19,10 @@ def get(url, data={}, api_key=misp_apikey):
"Content-Type": "application/json" "Content-Type": "application/json"
} }
full_url = urljoin(misp_url, url) 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 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" "Content-Type": "application/json"
} }
full_url = urljoin(misp_url, url) 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 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) eventlet.spawn_n(forward_zmq_to_socketio)
# Run the Socket.IO server # 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> </span>
</h4> </h4>
<h4 class="font-semibold ml-1"><strong>MISP Settings:</strong></h4> <template v-if="diagnosticLoading || isMISPOnline">
<div class="ml-3"> <h4 class="font-semibold ml-1"><strong>MISP Settings:</strong></h4>
<div v-if="diagnosticLoading" class="flex justify-center"> <div class="ml-3">
<span class="loading loading-dots loading-lg"></span> <div v-if="diagnosticLoading" class="flex justify-center">
</div> <span class="loading loading-dots loading-lg"></span>
<div </div>
v-for="(value, setting) in diagnostic['settings']" <div
:key="setting" v-for="(value, setting) in diagnostic['settings']"
> :key="setting"
<div> >
<label class="label cursor-pointer justify-start p-0 pt-1"> <div>
<input <label class="label cursor-pointer justify-start p-0 pt-1">
type="checkbox" <input
:checked="value" type="checkbox"
:value="setting" :checked="value"
:class="`checkbox ${value ? 'checkbox-success' : 'checkbox-danger'} [--fallback-bc:#cbd5e1]`" :value="setting"
disabled :class="`checkbox ${value ? 'checkbox-success' : 'checkbox-danger'} [--fallback-bc:#cbd5e1]`"
/> disabled
<span class="font-mono font-semibold text-base ml-3">{{ setting }}</span> />
</label> <span class="font-mono font-semibold text-base ml-3">{{ setting }}</span>
</label>
</div>
</div> </div>
</div> </div>
</div> </template>
</div> </div>
</div> </div>