refine handle_error