Skip to content

Commit 67a36fe

Browse files
author
喻斌
committed
bug fixed
1 parent 09cb745 commit 67a36fe

File tree

4 files changed

+52
-27
lines changed

4 files changed

+52
-27
lines changed

CatLib.Framework.sln

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 15
4-
VisualStudioVersion = 15.0.27004.2002
4+
VisualStudioVersion = 15.0.26430.4
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CatLib.Framework", "src\CatLib.Framework\CatLib.Framework.csproj", "{BBB2DAE2-638B-4419-9591-3CECCA312E4E}"
77
EndProject

src/CatLib.Framework.Tests/CatLib.Framework.Tests.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
<Compile Include="Network\ReceiveStateTests.cs" />
7373
<Compile Include="Network\TcpServer.cs" />
7474
<Compile Include="Random\RandomProviderTests.cs" />
75+
<Compile Include="Routing\TestMiddlewareException.cs" />
7576
<Compile Include="Socket\KcpConnectorTests.cs" />
7677
<Compile Include="Socket\KcpTestsServer.cs" />
7778
<Compile Include="Socket\SocketProviderTests.cs" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* This file is part of the CatLib package.
3+
*
4+
* (c) Yu Bin <[email protected]>
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*
9+
* Document: http://catlib.io/
10+
*/
11+
12+
using System;
13+
using System.Reflection;
14+
using CatLib.API.Routing;
15+
using CatLib.Routing;
16+
using Microsoft.VisualStudio.TestTools.UnitTesting;
17+
18+
namespace CatLib.Tests.Routing
19+
{
20+
[TestClass]
21+
public class TestMiddlewareException
22+
{
23+
[TestMethod]
24+
[ExpectedException(typeof(TargetInvocationException))]
25+
public void TestMiddlewareThrow()
26+
{
27+
var app = new Application();
28+
app.Bootstrap();
29+
app.OnFindType((t) =>
30+
{
31+
return Type.GetType(t);
32+
});
33+
app.Register(new RoutingProvider());
34+
var router = app.Make<IRouter>();
35+
router.Reg("test://throw", () =>
36+
{
37+
string str = null;
38+
var l = str.Length;
39+
});
40+
41+
router.Dispatch("test://throw");
42+
}
43+
}
44+
}

src/CatLib.Framework/Routing/Route.cs

+6-26
Original file line numberDiff line numberDiff line change
@@ -310,37 +310,17 @@ private void DispatchToAction(Request request, Response response)
310310
/// <param name="callback">完成中间件的回调</param>
311311
private void ThroughRouteMiddleware(Request request, Response response, object context, Action<Request, Response, object> callback)
312312
{
313-
try
313+
var middleware = GatherMiddleware();
314+
if (middleware != null)
314315
{
315-
var middleware = GatherMiddleware();
316-
if (middleware != null)
317-
{
318-
middleware.Do(request, response, (req, res) =>
319-
{
320-
callback.Invoke(request, response, context);
321-
});
322-
}
323-
else
316+
middleware.Do(request, response, (req, res) =>
324317
{
325318
callback.Invoke(request, response, context);
326-
}
319+
});
327320
}
328-
catch (Exception ex)
321+
else
329322
{
330-
var count = 0;
331-
while (count++ < 255)
332-
{
333-
if (ex.InnerException == null)
334-
{
335-
throw ex;
336-
}
337-
ex = ex.InnerException;
338-
}
339-
340-
if (count >= 255)
341-
{
342-
throw new RuntimeException("Route Error stack overflow. There may be an infinite loop. url: [" + request.Uri + "]");
343-
}
323+
callback.Invoke(request, response, context);
344324
}
345325
}
346326

0 commit comments

Comments
 (0)