detecting 401 and return error