sde1000 / quicktill

Figure out where all the money and stock went to
GNU General Public License v3.0
43 stars 8 forks source link

Square Terminal needs more helpful error messages on failed connections #255

Closed sde1000 closed 1 year ago

sde1000 commented 1 year ago

See this traceback:

2023-04-14 11:00:02,699 ERROR quicktill.till
  Exception caught at top level
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 159, in _new_conn
    conn = connection.create_connection(
  File "/usr/lib/python3/dist-packages/urllib3/util/connection.py", line 61, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
  File "/usr/lib/python3.8/socket.py", line 918, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -3] Temporary failure in name resolution

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 665, in urlopen
    httplib_response = self._make_request(
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 376, in _make_request
    self._validate_conn(conn)
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 996, in _validate_conn
    conn.connect()
  File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 314, in connect
    conn = self._new_conn()
  File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 171, in _new_conn
    raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.VerifiedHTTPSConnection object at 0x7f426910f760>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/requests/adapters.py", line 439, in send
    resp = conn.urlopen(
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 719, in urlopen
    retries = retries.increment(
  File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 436, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='connect.squareup.com', port=443): Max retries exceeded with url: /v2/terminals/checkouts (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f426910f760>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/quicktill/till.py", line 291, in run
    ui_gtk.run(
  File "/usr/lib/python3/dist-packages/quicktill/ui_gtk.py", line 627, in run
    tillconfig.mainloop.iterate()
  File "/usr/lib/python3/dist-packages/quicktill/event_glib.py", line 23, in iterate
    raise self._exc_info[0].with_traceback(
  File "/usr/lib/python3/dist-packages/quicktill/event_glib.py", line 68, in _call
    self._func()
  File "/usr/lib/python3/dist-packages/quicktill/squareterminal.py", line 517, in _timer_update
    self.update()
  File "/usr/lib/python3/dist-packages/quicktill/squareterminal.py", line 558, in update
    checkout = self.session.create_terminal_checkout(c)
  File "/usr/lib/python3/dist-packages/quicktill/squareterminal.py", line 363, in create_terminal_checkout
    r = self.session.post(self.api + "terminals/checkouts",
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 581, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='connect.squareup.com', port=443): Max retries exceeded with url: /v2/terminals/checkouts (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f426910f760>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution'))
2023-04-14 11:00:02,748 INFO quicktill.till
  Shutting down

This was just a glitch - after the till started back up we were able to complete a Square transaction. It would be better to have a helpful error message when the API connection fails, though!

sde1000 commented 1 year ago

It appears communication errors during refunds can leave things in a state where the refund exists in Square but not on the till. Not sure yet how we get into this state — the idempotency key is supposed to be committed to the database for the pending refund payment before we even attempt communication.