correctly handle rejected errors and promises