Return proper response code for delete by query api in the case of failures.
Closes #2963