trade.js: ixes and improvements to error handling