Wrap error messages into a standard javascript error object