Skip to content
Snippets Groups Projects
Commit f44cc3c4 authored by Alberto LIVIO BECCARIA's avatar Alberto LIVIO BECCARIA
Browse files

Fix: detect failure (timeout...) on login (no token -> following requests were unauthorized).

parent e99069e9
No related branches found
No related tags found
No related merge requests found
......@@ -3,7 +3,21 @@
API_BASE_URL=https://labmanager-api.edu-al.unipmn.it/api/1.0
function getTokenJSON() {
echo `curl -s -k --max-time 10 -X POST -H "Content-Type: application/json" -d "{\"login\":\"guest\",\"pwd\":\"\"}" ${API_BASE_URL}/login`
# store the whole response with the status at the end
HTTP_RESPONSE=$(curl -s -k -w "HTTPSTATUS:%{http_code}" --max-time 10 -X POST -H "Content-Type: application/json" -d "{\"login\":\"guest\",\"pwd\":\"\"}" ${API_BASE_URL}/login)
# extract the body
HTTP_BODY=$(echo "$HTTP_RESPONSE" | sed -e 's/HTTPSTATUS\:.*//g')
# extract the status
HTTP_STATUS=$(echo "$HTTP_RESPONSE" | tr -d '\n' | sed -e 's/.*HTTPSTATUS://')
# check the status
if [[ $HTTP_STATUS -ne 200 ]]
then
echo "Error authenticating to server (http_status=$HTTP_STATUS)"
exit 1
else
echo $HTTP_BODY
fi
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment