microsoft/teams.net
Publicmirrored fromhttps://github.com/microsoft/teams.netAvailable
Libraries/Microsoft.Teams.AI/Prompts/ChatPrompt/ChatPrompt.Errors.cs
28lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | namespace Microsoft.Teams.AI.Prompts; |
| 5 | |
| 6 | public partial class ChatPrompt<TOptions> |
| 7 | { |
| 8 | public IChatPrompt<TOptions> OnError(Action<Exception> onError) |
| 9 | { |
| 10 | ErrorEvent += (_, ex) => onError(ex); |
| 11 | return this; |
| 12 | } |
| 13 | |
| 14 | public IChatPrompt<TOptions> OnError(Func<Exception, Task> onError) |
| 15 | { |
| 16 | ErrorEvent += (_, ex) => |
| 17 | { |
| 18 | _ = onError(ex).ContinueWith(t => |
| 19 | { |
| 20 | if (t.IsFaulted) |
| 21 | { |
| 22 | Logger.Error(t.Exception); |
| 23 | } |
| 24 | }, TaskScheduler.Default); |
| 25 | }; |
| 26 | return this; |
| 27 | } |
| 28 | } |
| 29 | |