fix UTF-8 error message handling

using escape causes api to crash when sending utf-8 error messages.
changed escape to encodeURIComponent