Cleanup - centralize the log handling

This commit is contained in:
2024-08-27 12:16:01 -05:00
parent d8891ec75f
commit a6b7fc7afe
15 changed files with 124 additions and 180 deletions

View File

@@ -1,6 +1,7 @@
#!/bin/bash
#set -x
set -e
. helpers.sh
mkdir -p temp
ErrorLogLevel=err
@@ -29,8 +30,7 @@ while [[ $# -gt 0 ]]; do
shift; shift
done
msg="Querying for markets: _${markets}_ query string: _${queryString}_"
systemd-cat -t "`basename $0` $1" -p debug <<< ${msg}
log "Querying for markets: _${markets}_ query string: _${queryString}_" debug
curl -s -X GET "https://api.schwabapi.com/marketdata/v1/markets${queryString}" \
-H "Authorization: Bearer $(<access_token.dat)" > temp/markets.tmp.$$.json
@@ -39,11 +39,11 @@ curl -s -X GET "https://api.schwabapi.com/marketdata/v1/markets${queryString}" \
marketsCheck=$(jq -e -r '.. | .isOpen?' temp/markets.tmp.$$.json | grep -v null | wc -l)
if [[ ${marketsCheck} -eq 0 ]]; then
errMsg="ERROR: THE RESPONSE IS INCORRECT! markets: _${markets}_ Check: _${marketsCheck}_ check file _temp/markets.tmp.$$.json_"
systemd-cat -t "`basename $0` $1" -p ${ErrorLogLevel} <<< ${errMsg}
if [[ "${ErrorLogLevel}" == "err" ]]; then
>&2 echo "${errMsg}"
throw ${errMsg} ${ErrorLogLevel}
else
log ${errMsg} ${ErrorLogLevel}
fi
exit 2
else
jq < temp/markets.tmp.$$.json
rm temp/markets.tmp.$$.json