Fixing error handling with promises