Thursday 17 May 2018

How do I handle this error?

My app uses an encrypted key as a query string. But since query string cannot parse special characters, I have to encode them usingencodeURIComponent() When the url with the query string is accessed, it sends the query string back to the server, decodes it before it is decrypted. If I manually alter the query string to some malformed URI, I get an error.Error: Malformed UTF-8 data at Object.stringify (D:\Projects\healme\node_modules\crypto-js\core.js:478:24) at WordArray.init.toString (D:\Projects\healme\node_modules\crypto-js\core.js:215:38) at D:\Projects\healme\routers\routes.js:29:37 at Layer.handle [as handle_request] (D:\Projects\healme\node_modules\express\lib\router\layer.js:95:5) at next (D:\Projects\healme\node_modules\express\lib\router\route.js:137:13) at Route.dispatch (D:\Projects\healme\node_modules\express\lib\router\route.js:112:3) at Layer.handle [as handle_request] (D:\Projects\healme\node_modules\express\lib\router\layer.js:95:5) at D:\Projects\healme\node_modules\express\lib\router\index.js:281:22 at Function.process_params (D:\Projects\healme\node_modules\express\lib\router\index.js:335:12) at next (D:\Projects\healme\node_modules\express\lib\router\index.js:275:10) What can I do so that if an invalid query string/URI is entered into the browser, I show a custom page saying an error has occurred?I try to use a try and catch block but it doesn't seem to work.try { decodeURIComponent(req.query.key); catch (e) { resp.redirect('/error.html'); }

Submitted May 17, 2018 at 06:06PM by eggtart_prince

No comments:

Post a Comment