public async Task <ResultSetPaging> GetSearch([FromBody] SearchRequest body) { // Due to the bug in Alfresco, which will return 403 when permissions changes and search engine has delay, // there is a loop that will try to call it over and over if the search engine returns 200 Exception lastException = null; var mustResponseUntil = DateTime.UtcNow.AddSeconds(20); while (DateTime.UtcNow <= mustResponseUntil) { try { return(await _alfrescoHttpClient.Search(body)); } catch (Exception e) { lastException = e; await Task.Delay(1000); // Do nothing, keep in looping } } if (lastException != null) { throw lastException; } throw new BadRequestException("", "Search engine encountered an error"); }