-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
40 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/SIL.Machine.AspNetCore/Services/CancellationInterceptor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
namespace SIL.Machine.AspNetCore.Services; | ||
|
||
public class CancellationInterceptor : Interceptor | ||
{ | ||
private readonly ILogger<CancellationInterceptor> _logger; | ||
|
||
public CancellationInterceptor(ILogger<CancellationInterceptor> logger) | ||
{ | ||
_logger = logger; | ||
} | ||
|
||
public override async Task<TResponse> UnaryServerHandler<TRequest, TResponse>( | ||
TRequest request, | ||
ServerCallContext context, | ||
UnaryServerMethod<TRequest, TResponse> continuation | ||
) | ||
{ | ||
try | ||
{ | ||
return await continuation(request, context); | ||
} | ||
catch (Exception ex) | ||
{ | ||
if (ex is OperationCanceledException) | ||
{ | ||
_logger.LogInformation(exception: ex, message: null); | ||
return null; | ||
Check warning on line 27 in src/SIL.Machine.AspNetCore/Services/CancellationInterceptor.cs GitHub Actions / Build on ubuntu-20.04
Check warning on line 27 in src/SIL.Machine.AspNetCore/Services/CancellationInterceptor.cs GitHub Actions / Build on ubuntu-20.04
Check warning on line 27 in src/SIL.Machine.AspNetCore/Services/CancellationInterceptor.cs GitHub Actions / Build on windows-latest
Check warning on line 27 in src/SIL.Machine.AspNetCore/Services/CancellationInterceptor.cs GitHub Actions / Build on windows-latest
|
||
} | ||
else | ||
{ | ||
throw; | ||
} | ||
} | ||
} | ||
} |