fix handling of errors in promises