add set error code method.

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>