[api] turn all errors in do_branch into exceptions.

- adding generic project name validation method
- This is changing in two relative obscure cases the return error code, but to the correct value.
- Moving more generic errors to the exception lib and rename some.