/merge slash command returns an error even when it succeeds

Summary

Sometimes the /merge slash command returns an error although the merge was successful.

Steps to reproduce

Use /merge slash command for opened MR.

What is the current bug behavior?

Sometimes an error is displayed:

$('.mr-widget-body').html("<h4>\n<i class=\"fa fa-exclamation-triangle\"><\/i>\nThis merge request failed to be merged automatically\n<\/h4>\n<p>\nPlease reload the page to find out the reason.\n<\/p>\n");

What is the expected correct behavior?

User always gets correct information

Possible fixes

This probably happens due to the fact a merge request is merged async. In case the client calls merge_widget_refresh before the merge is actually picked it returns this error. The condition in that method needs to be rewritten.