Fix code style issue
Refactor how API errors are created