Skip to content

Commit ee57b9a

Browse files
committed
added additional exception to handle 404
Signed-off-by: Neil South <[email protected]>
1 parent b482888 commit ee57b9a

File tree

5 files changed

+84
-5
lines changed

5 files changed

+84
-5
lines changed

src/TaskManager/Plug-ins/Argo/ArgoClient.cs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
using Ardalis.GuardClauses;
2121
using Microsoft.Extensions.Logging;
2222
using Monai.Deploy.WorkflowManager.TaskManager.Argo.Logging;
23+
using System.Net;
24+
using Monai.Deploy.WorkflowManager.TaskManager.Argo.Exceptions;
2325

2426
namespace Monai.Deploy.WorkflowManager.TaskManager.Argo
2527
{
@@ -78,7 +80,23 @@ public async Task<Workflow> Argo_StopWorkflowAsync(string argoNamespace, string
7880

7981
const string method = "PUT";
8082
var content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(body));
81-
return await SendRequest<Workflow>(content, urlBuilder, method, new CancellationToken()).ConfigureAwait(false);
83+
try
84+
{
85+
return await SendRequest<Workflow>(content, urlBuilder, method, new CancellationToken()).ConfigureAwait(false);
86+
}
87+
catch (ApiException<Error> ex)
88+
{
89+
if (ex.StatusCode == (int)HttpStatusCode.NotFound)
90+
{
91+
throw new ArgoWorkflowNotFoundException(body.Name, ex);
92+
}
93+
throw;
94+
}
95+
catch (Exception)
96+
{
97+
throw;
98+
}
99+
82100

83101
}
84102

@@ -93,7 +111,22 @@ public async Task<Workflow> Argo_TerminateWorkflowAsync(string argoNamespace, st
93111

94112
const string method = "PUT";
95113
var content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(body));
96-
return await SendRequest<Workflow>(content, urlBuilder, method, new CancellationToken()).ConfigureAwait(false);
114+
try
115+
{
116+
return await SendRequest<Workflow>(content, urlBuilder, method, new CancellationToken()).ConfigureAwait(false);
117+
}
118+
catch (ApiException<Error> ex)
119+
{
120+
if (ex.StatusCode == (int)HttpStatusCode.NotFound)
121+
{
122+
throw new ArgoWorkflowNotFoundException(body.Name, ex);
123+
}
124+
throw;
125+
}
126+
catch (Exception)
127+
{
128+
throw;
129+
}
97130
}
98131

99132
public async Task<WorkflowTemplate?> Argo_GetWorkflowTemplateAsync(string argoNamespace, string name, string? getOptionsResourceVersion)

src/TaskManager/Plug-ins/Argo/ArgoPlugin.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
using Monai.Deploy.WorkflowManager.TaskManager.API.Models;
3131
using Monai.Deploy.WorkflowManager.TaskManager.Argo.Logging;
3232
using Newtonsoft.Json;
33+
using Monai.Deploy.WorkflowManager.TaskManager.Argo.Exceptions;
3334

3435
[assembly: PlugIn()]
3536
namespace Monai.Deploy.WorkflowManager.TaskManager.Argo
@@ -916,10 +917,14 @@ public override async Task HandleTimeout(string identity)
916917
Namespace = _namespace
917918
});
918919
}
919-
catch (Exception ex)
920+
catch (ArgoWorkflowNotFoundException ex)
920921
{
921922
_logger.ExecptionStoppingArgoWorkflow(identity, ex);
922923
}
924+
catch (Exception)
925+
{
926+
throw;
927+
}
923928
}
924929

925930
public async Task<WorkflowTemplate> CreateArgoTemplate(string template)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2022 MONAI Consortium
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
using System.Runtime.Serialization;
18+
19+
namespace Monai.Deploy.WorkflowManager.TaskManager.Argo.Exceptions
20+
{
21+
[Serializable]
22+
public class ArgoWorkflowNotFoundException : Exception
23+
{
24+
public ArgoWorkflowNotFoundException(string argoWorkflowName)
25+
: base($"Argo workflow '{argoWorkflowName}' not found.")
26+
{
27+
}
28+
29+
public ArgoWorkflowNotFoundException(string? message, Exception? innerException) : base(message, innerException)
30+
{
31+
}
32+
33+
protected ArgoWorkflowNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context)
34+
{
35+
}
36+
37+
public ArgoWorkflowNotFoundException()
38+
{
39+
}
40+
}
41+
}

src/TaskManager/Plug-ins/Argo/ArtifactMappingNotFoundException.cs renamed to src/TaskManager/Plug-ins/Argo/Exceptions/ArtifactMappingNotFoundException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
using System.Runtime.Serialization;
1818

19-
namespace Monai.Deploy.WorkflowManager.TaskManager.Argo
19+
namespace Monai.Deploy.WorkflowManager.TaskManager.Argo.Exceptions
2020
{
2121
[Serializable]
2222
public class ArtifactMappingNotFoundException : Exception

src/TaskManager/Plug-ins/Argo/TemplateNotFoundException.cs renamed to src/TaskManager/Plug-ins/Argo/Exceptions/TemplateNotFoundException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
using System.Runtime.Serialization;
1818

19-
namespace Monai.Deploy.WorkflowManager.TaskManager.Argo
19+
namespace Monai.Deploy.WorkflowManager.TaskManager.Argo.Exceptions
2020
{
2121
[Serializable]
2222
public class TemplateNotFoundException : Exception

0 commit comments

Comments
 (0)