Skip to content

Commit 0163420

Browse files
committed
37515: Use status code as CommandException replacement for blank message
SVN r64560 |2019-09-26 23:04:15 +0000
1 parent f555e58 commit 0163420

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

java/src/org/labkey/remoteapi/CommandException.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
*/
1616
package org.labkey.remoteapi;
1717

18+
import org.apache.http.impl.EnglishReasonPhraseCatalog;
19+
20+
import java.util.Locale;
1821
import java.util.Map;
1922

2023
/**
@@ -71,13 +74,34 @@ public CommandException(String message, int statusCode, Map<String, Object> prop
7174
*/
7275
public CommandException(String message, int statusCode, Map<String, Object> properties, String responseText, String contentType)
7376
{
74-
super(message);
77+
super(buildMessage(message, statusCode));
7578
_statusCode = statusCode;
7679
_properties = properties;
7780
_responseText = responseText;
7881
_contentType = contentType;
7982
}
8083

84+
private static String buildMessage(String message, int statusCode)
85+
{
86+
if (statusCode == 0 || (message != null && !message.trim().isEmpty()))
87+
{
88+
return message;
89+
}
90+
91+
// Use status code as message if none is specified
92+
StringBuilder sb = new StringBuilder();
93+
sb.append(statusCode);
94+
try
95+
{
96+
String reasonPhrase = EnglishReasonPhraseCatalog.INSTANCE.getReason(statusCode, Locale.getDefault());
97+
sb.append(" : ");
98+
sb.append(reasonPhrase);
99+
}
100+
catch (IllegalArgumentException ignore) { /* Unknown status code */ }
101+
102+
return sb.toString();
103+
}
104+
81105
public String getContentType()
82106
{
83107
return _contentType;

0 commit comments

Comments
 (0)