You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -70,13 +70,13 @@ As you can see, you need to derive from MiddyNet, and specify the type of event
70
70
After your code is executed, Middy .NET will call the after methods of the middlewares in reverse order. You can use this to, for example, alter the response in some way (adding headers, for example).
71
71
72
72
### Handling errors
73
-
Errors can happen in the `Before` method of the middleware or in the `After` method of them. Although we capture those errors, we treat those them slightly different.
73
+
Errors can happen in the `Before` method of the middleware or in the `After` method of them. Although we capture those errors, we treat them slightly differently.
74
74
75
75
#### Errors on Before
76
76
When an exception is thrown by a middleware in the `Before` method, the exception is captured and added to the `MiddlewareBeforeExceptions` list, so that the following middlewares and the function can react to it.
77
77
78
78
#### Errors on Handler
79
-
When an exception is thrown by the function in its `Handle` method and before the `After` middlewares are called, the exception is captured in the `HandlerException` property of the context, so that the following middlewares can react to it.
79
+
When an exception is thrown by the function in its `Handle` method and before the `After` middlewares are called, the exception is captured in the `HandlerException` property of the context, so that the following middlewares' `After` method can react to it.
80
80
81
81
#### Errors on After
82
82
When an exception is thrown by a middleware in the `After` method, the exception is captured and added to the `MiddlewareAfterExceptions` list, so that the following middlewares can react to it.
Copy file name to clipboardExpand all lines: docs/source/intro/howitworks.rst
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,6 +3,6 @@ How it works
3
3
4
4
**MiddyNet** is a lightweight middleware engine. A middleware is a piece of code that can be run before or after your function is run. In the *before* section, middlewares are run in the same order that are added. In the *after* section, middlewares are run in the inverse order that are added. Usually, a middleware will only make sense to do anything in one of the sections.
5
5
6
-
Exceptions can be thrown by the middlewares and they are captured by the library. If the exception is thrown in the *before* section, the exception is made available to the following middlewares and eventually to your function via the context. If the exception is thrown in the *after* section, it's eventually thrown by the library as an *AggregateException*.
6
+
Exceptions can be thrown by the middlewares and they are captured by the library. If the exception is thrown in the *before* section, the exception is made available to the following middlewares and eventually to your function via the context. If the exception is thrown in the *handler* or in the *after* section, it's eventually thrown by the library as an *AggregateException*. Non cleaned ``MiddlewareBeforeExceptions`` will also be included in the resulting AggregateException.
7
7
8
8
**MiddyNet** also adds a Logger to log structured logging and a way to capture and propagate the TraceContext as described `here <https://www.w3.org/TR/trace-context/>`_.
Copy file name to clipboardExpand all lines: docs/source/started/middycontext.rst
+18-2Lines changed: 18 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,9 +15,25 @@ A ``Dictionary<string, object>`` filled with the information that the different
15
15
16
16
MiddlewareExceptions
17
17
--------------------
18
+
There are 4 properties and a method related to exceptions:
18
19
19
-
A ``List<Exception>``, with the exceptions thrown by the different middlewares.
20
+
* ``List<Exception> MiddlewareBeforeExceptions { get; }``, *Middleare with the exceptions thrown by the middlewares' *Before* method.
21
+
* ``Exception HandlerException { get; set; }``, with the exception thrown by the custom handler's *Handle* method.
22
+
* ``List<Exception> MiddlewareAfterExceptions { get; }``, with the exceptions thrown by the middlewares' *After* method.
23
+
* ``bool HasExceptions { get; }``, which tells if there are any exceptions in the aforementioned properties
24
+
* ``List<Exception> GetAllExceptions()``, which returns the exceptions in the three properties as a single list, in the same order as they happened.
25
+
26
+
You may want to check whether any exceptions occured before proceeding with your custom logic in the handler like so:
27
+
28
+
if (context.HasExceptions)
29
+
{
30
+
// do stuff...
31
+
context.MiddlewareBeforeExceptions.Clear();
32
+
}
33
+
34
+
This will prevent those exceptions to be returned at the end of the pipeline processing.
20
35
21
36
Logger
22
37
------
23
-
An object of type MiddyLogger to allow you to log structured logs. It uses the ``ILambdaLogger`` provided by AWS internally. See more information about the :doc:`/logger`.
38
+
An object of type MiddyLogger to allow you to log structured logs. It uses the ``ILambdaLogger`` provided by AWS internally. See more information about the :doc:`/logger`.
Copy file name to clipboardExpand all lines: docs/source/writing/writing.rst
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,4 +34,4 @@ The value of the property can be whatever you want, from a single type to a comp
34
34
35
35
Exceptions
36
36
----------
37
-
You don't need to catch exceptions in the middleware. The library will catch them for you and add them to the ``MiddlewareExceptions`` property.
37
+
You don't need to catch exceptions in the middleware. The library will catch them for you and add them to the context's corresponding exceptions collection (``MiddlewareBeforeExceptions``, ``HandlerException`` or ``MiddlewareAfterExceptions`` depending on where was the exception thrown).
0 commit comments