Refactor error API