Modify converting to capi error and simplify error type use