Fix returning errors to the json client.

These looks like typos. The previous code threw becase 'res' wasn't defined.