This looks fine to me, but instead of the global res variable please use local variables in the if blocks (and maybe give them a better name like err).
This looks fine to me, but instead of the global res variable please use local variables in the if blocks (and maybe give them a better name like err).