[JS] Made response callback code more robust