|
@@ -42,35 +42,56 @@ namespace EVCB_OCPP.WEBAPI.Handlers
|
|
|
|
|
|
return await base.SendAsync(request, cancellationToken)
|
|
|
.ContinueWith(task =>
|
|
|
- {
|
|
|
-
|
|
|
- var response = task.Result;
|
|
|
-
|
|
|
- if (response.Content != null)
|
|
|
+ {
|
|
|
+
|
|
|
+ if(task.IsFaulted)
|
|
|
{
|
|
|
- apiLogEntry.ResponseContentBody = response.Content.ReadAsStringAsync().Result;
|
|
|
- apiLogEntry.ResponseContentType = response.Content.Headers.ContentType.MediaType;
|
|
|
- apiLogEntry.ResponseHeaders = WebApiHelper.SerializeHeaders(response.Content.Headers);
|
|
|
- }
|
|
|
+ var result = new CPOOuterResponse() { StatusCode = (int)CPO_StatusCode.UnexpectedError, StatusMessage = CPO_StatusMessage.ERROR_MSG_Global_UNEXPECTEDERROR };
|
|
|
|
|
|
- int errorMessageIndex = apiLogEntry.ResponseContentBody.IndexOf(",\"ErrorDetail\"");
|
|
|
- string endTag = apiLogEntry.ResponseContentBody.Last().ToString();
|
|
|
+ apiLogEntry.ResponseContentBody = JsonConvert.SerializeObject(result, EVCBConfiguration.JSONSERIALIZER_FORMAT);
|
|
|
+ apiLogEntry.ResponseContentType = "";
|
|
|
+ apiLogEntry.ResponseHeaders = "";
|
|
|
|
|
|
- if (errorMessageIndex > 0)
|
|
|
- {
|
|
|
- string errorMsg = apiLogEntry.ResponseContentBody.Substring(errorMessageIndex).Remove(0, 16);
|
|
|
- apiLogEntry.ResponseContentBody = apiLogEntry.ResponseContentBody.Remove(errorMessageIndex).Remove(0, 1);
|
|
|
apiLogEntry.ErrorOn = DateTime.Now;
|
|
|
- apiLogEntry.ErrorMsg = errorMsg.Remove(errorMsg.Count() - 2).Replace("'"," ");
|
|
|
-
|
|
|
- response = request.CreateResponse(response.StatusCode, JsonConvert.DeserializeObject("{" + apiLogEntry.ResponseContentBody + "}"));
|
|
|
+ apiLogEntry.ErrorMsg = task.Exception.ToString().Replace("'", " ");
|
|
|
+
|
|
|
+ apiLogEntry.ResponseStatusCode = (int) HttpStatusCode.InternalServerError;
|
|
|
+ apiLogEntry.ResponseTimestamp = DateTime.Now;
|
|
|
+ WriteLog(apiLogEntry);
|
|
|
+ return request.CreateResponse(HttpStatusCode.InternalServerError, result);
|
|
|
}
|
|
|
+ else
|
|
|
+ {
|
|
|
+ var response = task.Result;
|
|
|
+
|
|
|
+ if (response.Content != null)
|
|
|
+ {
|
|
|
+ apiLogEntry.ResponseContentBody = response.Content.ReadAsStringAsync().Result;
|
|
|
+ apiLogEntry.ResponseContentType = response.Content.Headers.ContentType.MediaType;
|
|
|
+ apiLogEntry.ResponseHeaders = WebApiHelper.SerializeHeaders(response.Content.Headers);
|
|
|
+ }
|
|
|
+
|
|
|
+ int errorMessageIndex = apiLogEntry.ResponseContentBody.IndexOf(",\"ErrorDetail\"");
|
|
|
+ string endTag = apiLogEntry.ResponseContentBody.Last().ToString();
|
|
|
|
|
|
- apiLogEntry.ResponseStatusCode = (int)response.StatusCode;
|
|
|
- apiLogEntry.ResponseTimestamp = DateTime.Now;
|
|
|
- WriteLog(apiLogEntry);
|
|
|
+ if (errorMessageIndex > 0)
|
|
|
+ {
|
|
|
+ string errorMsg = apiLogEntry.ResponseContentBody.Substring(errorMessageIndex).Remove(0, 16);
|
|
|
+ apiLogEntry.ResponseContentBody = apiLogEntry.ResponseContentBody.Remove(errorMessageIndex).Remove(0, 1);
|
|
|
+ apiLogEntry.ErrorOn = DateTime.Now;
|
|
|
+ apiLogEntry.ErrorMsg = errorMsg.Remove(errorMsg.Count() - 2).Replace("'", " ");
|
|
|
|
|
|
- return response;
|
|
|
+ response = request.CreateResponse(response.StatusCode, JsonConvert.DeserializeObject("{" + apiLogEntry.ResponseContentBody + "}"));
|
|
|
+ }
|
|
|
+
|
|
|
+ apiLogEntry.ResponseStatusCode = (int)response.StatusCode;
|
|
|
+ apiLogEntry.ResponseTimestamp = DateTime.Now;
|
|
|
+ WriteLog(apiLogEntry);
|
|
|
+
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}, cancellationToken);
|
|
|
}
|
|
|
|