api: refactor error helper