Normalise error messages in JS

Change-Id: I6bbbee2b4f6c01d158f147b3097618b3cffe475f