Handles API errors more gracefully, fixes issue #31