Skip to content

Commit b5e7aa9

Browse files
committed
added error code return
1 parent 9f7dbd8 commit b5e7aa9

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

LinkRouter/App/Configuration/Config.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,6 @@ public void CompileRoutes()
102102
CompiledRoutes = compiledRoutes
103103
.ToArray();
104104
}
105+
106+
[JsonIgnore] public static Regex ErrorCodePattern = new(@"\s*\-\>\s*(\d+)\s*$", RegexOptions.Compiled | RegexOptions.CultureInvariant);
105107
}

LinkRouter/App/Http/Controllers/RedirectController.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ public class RedirectController : Controller
1010
{
1111

1212
private readonly Config Config;
13-
1413

1514
private readonly Counter RouteCounter = Metrics.CreateCounter(
1615
"linkrouter_requests",
@@ -39,7 +38,6 @@ public RedirectController(Config config)
3938
[HttpGet("/{*path}")]
4039
public async Task<ActionResult> RedirectToExternalUrl(string path)
4140
{
42-
4341
if (!path.EndsWith("/"))
4442
path += "/";
4543

@@ -65,6 +63,13 @@ public async Task<ActionResult> RedirectToExternalUrl(string path)
6563

6664
string redirectUrl = redirectRoute.RedirectUrl;
6765

66+
if (Config.ErrorCodePattern.IsMatch(redirectUrl))
67+
{
68+
var errorCodeMatch = Config.ErrorCodePattern.Match(redirectUrl);
69+
var errorCode = int.Parse(errorCodeMatch.Groups[1].Value);
70+
return StatusCode(errorCode);
71+
}
72+
6873
foreach (var placeholder in redirectRoute.Placeholders)
6974
{
7075
var value = match.Groups[placeholder.Value].Value;

0 commit comments

Comments
 (0)