[JavaScript] Quick solution for URI malformed / malformed URI sequence errors
I’ll introduce a quick solution for URI malformed / malformed URI sequence errors in JavaScript.
Message
URIError: malformed URI sequence (Firefox) URIError: URI malformed (Chrome)
Error Type
URIError
What went wrong?
URI encoding or decoding was not successful. The decodeURI or encodeURI, encodeURIComponent, decodeURIComponent functions had invalid arguments, so the functions could not properly encode or decode.
Handle it roughly with try…catch statements.
// Decode encoded URL parameters
decodeURIParams(encodedURIParams) {
try {
return decodeURIComponent(encodedURIParams);
} catch (err) {
return '';
}
}
That’s all from the Gemba where I occasionally encounter URI malformed errors.