fix error handling in rest api

Change-Id: Ibf3b35f1dd6cce2f8068fe2d406ce99beeeaddbd
Reviewed-on: http://review.couchbase.org/44330
Reviewed-by: Xiaomei Zhang <xiaomeizhangatwork@gmail.com>
Tested-by: Yu Sui <ysui68@gmail.com>