Send email if access token is invalid

Hi there! I will be making API calls daily and was wondering how can I know if the access token I’m passing is invalid just so I can send an email to myself informing the same.

You will receive a 401 response code back with a json body indicating the token is either expiring or invalid. Expired tokens eventually are removed from the system which it will then start returning the invalid token response.