@@ -67,13 +67,23 @@ public String fetchData(ServerRequest req) throws DataAccessException {
6767 }
6868 final int responseCode = fileInfo .getResponseCode ();
6969 if (responseCode > 305 || responseCode < 200 ) {
70- final String responseMsg = StringUtils .isEmpty (fileInfo .getResponseCodeMsg ())
70+ String responseMsg = StringUtils .isEmpty (fileInfo .getResponseCodeMsg ())
7171 ? "Unknown error"
7272 : fileInfo .getResponseCodeMsg ();
73- return makeError (source ,
74- "Unable to retrieve the FITS file: " + responseCode + " " + responseMsg );
73+
74+ String message = switch (responseCode ) {
75+ case 400 -> "400 Bad Request: unknown query parameter, or malformed alert ID" ;
76+ case 401 -> "401 Unauthorized: missing or invalid token" ;
77+ case 404 -> "404 Not Found: no alert exists for the given ID" ;
78+ case 415 -> "415 Unsupported Media Type: unrecognised RESPONSEFORMAT value" ;
79+ case 500 -> "500 Internal Server Error: alert service internal error." ;
80+ default -> "Unable to retrieve the FITS file: " + responseCode + " " + responseMsg ;
81+ };
82+
83+ return makeError (source , message );
7584 }
7685
86+
7787 FileAnalysisReport report = FileAnalysis .analyze (fileInfo , Details , ANALYZER_ID , Collections .emptyMap ());
7888 return makeSuccess (source , fileInfo , report );
7989 } catch (Exception e ) {
@@ -169,9 +179,9 @@ private static String makeAlertServiceUrl(String alertId) throws DataAccessExcep
169179 throw new DataAccessException ("Missing required property: " + ALERT_SERVICE_BASE_URL_PROP );
170180 }
171181 final String joiner = baseUrl .contains ("?" ) ? "&" : "?" ;
172- return baseUrl + joiner +
173- ALERT_ID + "=" + URLEncoder .encode (alertId , StandardCharsets .UTF_8 ) + "&" +
174- RESPONSEFORMAT + "=" + FITS_RESPONSE_FORMAT ;
182+ return String . format ( "%s%s%s=%s&%s=%s" ,
183+ baseUrl , joiner , ALERT_ID , URLEncoder .encode (alertId , StandardCharsets .UTF_8 ),
184+ RESPONSEFORMAT , FITS_RESPONSE_FORMAT ) ;
175185 }
176186
177187 private static JSONObject baseResponse (String source , boolean success , String message ) {
0 commit comments