Add better API exception handling