Skip to content

Commit 44dbc72

Browse files
authored
concord-server: default message for unexpected errors (#1096)
1 parent 3af9593 commit 44dbc72

File tree

6 files changed

+121
-0
lines changed

6 files changed

+121
-0
lines changed

plugins/tasks/misc/src/main/java/com/walmartlabs/concord/plugins/misc/CollectionsTaskV2.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
package com.walmartlabs.concord.plugins.misc;
22

3+
/*-
4+
* *****
5+
* Concord
6+
* -----
7+
* Copyright (C) 2017 - 2025 Walmart Inc.
8+
* -----
9+
* Licensed under the Apache License, Version 2.0 (the "License");
10+
* you may not use this file except in compliance with the License.
11+
* You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS,
17+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* See the License for the specific language governing permissions and
19+
* limitations under the License.
20+
* =====
21+
*/
22+
323
import com.google.common.collect.Lists;
424
import com.walmartlabs.concord.runtime.v2.sdk.DryRunReady;
525
import com.walmartlabs.concord.runtime.v2.sdk.Task;

plugins/tasks/misc/src/main/java/com/walmartlabs/concord/plugins/misc/EnvTaskV2.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
package com.walmartlabs.concord.plugins.misc;
22

3+
/*-
4+
* *****
5+
* Concord
6+
* -----
7+
* Copyright (C) 2017 - 2025 Walmart Inc.
8+
* -----
9+
* Licensed under the Apache License, Version 2.0 (the "License");
10+
* you may not use this file except in compliance with the License.
11+
* You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS,
17+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* See the License for the specific language governing permissions and
19+
* limitations under the License.
20+
* =====
21+
*/
22+
323
import com.walmartlabs.concord.runtime.v2.sdk.DryRunReady;
424
import com.walmartlabs.concord.runtime.v2.sdk.Task;
525

server/impl/src/main/java/com/walmartlabs/concord/server/ApiServerModule.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public void configure(Binder binder) {
7272
// RequestErrorHandler
7373

7474
newSetBinder(binder, RequestErrorHandler.class).addBinding().to(FormRequestErrorHandler.class);
75+
newSetBinder(binder, RequestErrorHandler.class).addBinding().to(GenericRequestErrorHandler.class);
7576

7677
// ContextHandlerConfigurator
7778

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package com.walmartlabs.concord.server;
2+
3+
/*-
4+
* *****
5+
* Concord
6+
* -----
7+
* Copyright (C) 2017 - 2025 Walmart Inc.
8+
* -----
9+
* Licensed under the Apache License, Version 2.0 (the "License");
10+
* you may not use this file except in compliance with the License.
11+
* You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS,
17+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* See the License for the specific language governing permissions and
19+
* limitations under the License.
20+
* =====
21+
*/
22+
23+
import com.walmartlabs.concord.server.boot.RequestErrorHandler;
24+
import com.walmartlabs.concord.server.console.ResponseTemplates;
25+
import org.apache.http.HttpHeaders;
26+
import org.eclipse.jetty.http.MimeTypes;
27+
28+
import javax.inject.Inject;
29+
import javax.servlet.http.HttpServletRequest;
30+
import javax.servlet.http.HttpServletResponse;
31+
import java.io.IOException;
32+
import java.io.OutputStream;
33+
import java.nio.charset.StandardCharsets;
34+
import java.util.Map;
35+
36+
public class GenericRequestErrorHandler implements RequestErrorHandler {
37+
38+
private final ResponseTemplates responseTemplates;
39+
40+
@Inject
41+
public GenericRequestErrorHandler(ResponseTemplates responseTemplates) {
42+
this.responseTemplates = responseTemplates;
43+
}
44+
45+
@Override
46+
public boolean handle(HttpServletRequest request, HttpServletResponse response) throws IOException {
47+
Map<String, Object> args = Map.of("statusCode", response.getStatus());
48+
49+
OutputStream out = response.getOutputStream();
50+
response.setCharacterEncoding(StandardCharsets.UTF_8.name());
51+
String accept = request.getHeader(HttpHeaders.ACCEPT);
52+
53+
if (accept.toLowerCase().startsWith(MimeTypes.Type.APPLICATION_JSON.asString())) {
54+
response.setContentType(MimeTypes.Type.APPLICATION_JSON_UTF_8.asString());
55+
out.write("{\"error\": \"An unexpected error occurred.\"}".getBytes(StandardCharsets.UTF_8));
56+
} else {
57+
responseTemplates.genericError(out, args);
58+
response.setContentType(MimeTypes.Type.TEXT_HTML.asString());
59+
}
60+
61+
return true;
62+
}
63+
64+
}

server/impl/src/main/java/com/walmartlabs/concord/server/console/ResponseTemplates.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public class ResponseTemplates {
3939
private final Mustache processError;
4040
private final Mustache inProgressWait;
4141
private final Mustache formNotFound;
42+
private final Mustache genericError;
4243

4344
public ResponseTemplates() {
4445
MustacheFactory mf = new DefaultMustacheFactory();
@@ -47,6 +48,7 @@ public ResponseTemplates() {
4748
processError = mf.compile("com/walmartlabs/concord/server/console/processError.html");
4849
inProgressWait = mf.compile("com/walmartlabs/concord/server/console/inProgress.html");
4950
formNotFound = mf.compile("com/walmartlabs/concord/server/console/formNotFound.html");
51+
genericError = mf.compile("com/walmartlabs/concord/server/console/genericError.html");
5052
}
5153

5254
private ResponseBuilder html(Mustache m, ResponseBuilder r, Map<String, Object> args) {
@@ -79,4 +81,10 @@ public void formNotFound(OutputStream out, Map<String, Object> args) throws IOEx
7981
formNotFound.execute(w, args);
8082
}
8183
}
84+
85+
public void genericError(OutputStream out, Map<String, Object> args) throws IOException {
86+
try (OutputStreamWriter w = new OutputStreamWriter(out)) {
87+
genericError.execute(w, args);
88+
}
89+
}
8290
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{{> header}}
2+
3+
<div class="ui negative message">
4+
<div class="header">Unexpected Error - {{ statusCode }}</div>
5+
<p>The application has encountered an unknown error. Check request URL and parameters.</p>
6+
</div>
7+
8+
{{> footer}}

0 commit comments

Comments
 (0)