Skip to content

Commit

Permalink
Change detail field name
Browse files Browse the repository at this point in the history
  • Loading branch information
TharmiganK committed May 27, 2024
1 parent 90ee339 commit f6148d4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
22 changes: 11 additions & 11 deletions ballerina/http_client_endpoint.bal
Original file line number Diff line number Diff line change
Expand Up @@ -680,37 +680,37 @@ isolated function createResponseError(int statusCode, string reasonPhrase, map<s
isolated function createStatusCodeResponseBindingError(int statusCode, string reasonPhrase, map<string[]> headers,
anydata body = ()) returns ClientError {
if 100 <= statusCode && statusCode <= 399 {
return error StatusCodeResponseBindingError(reasonPhrase, statusCode = statusCode, headers = headers, body = body, fromDefaultStatusCodeResponse = false);
return error StatusCodeResponseBindingError(reasonPhrase, statusCode = statusCode, headers = headers, body = body, fromDefaultStatusCodeMapping = false);
} else if 400 <= statusCode && statusCode <= 499 {
return error StatusCodeBindingClientRequestError(reasonPhrase, statusCode = statusCode, headers = headers, body = body, fromDefaultStatusCodeResponse = false);
return error StatusCodeBindingClientRequestError(reasonPhrase, statusCode = statusCode, headers = headers, body = body, fromDefaultStatusCodeMapping = false);
} else {
return error StatusCodeBindingRemoteServerError(reasonPhrase, statusCode = statusCode, headers = headers, body = body, fromDefaultStatusCodeResponse = false);
return error StatusCodeBindingRemoteServerError(reasonPhrase, statusCode = statusCode, headers = headers, body = body, fromDefaultStatusCodeMapping = false);
}
}

isolated function createStatusCodeResponseDataBindingError("header"|"mediaType"|"payload"|"generic" errorType, boolean fromDefaultStatusCodeResponse,
isolated function createStatusCodeResponseDataBindingError("header"|"mediaType"|"payload"|"generic" errorType, boolean fromDefaultStatusCodeMapping,
int statusCode, string reasonPhrase, map<string[]> headers, anydata body = (), error? cause = ()) returns ClientError {
match (errorType) {
"header" => {
if cause is HeaderValidationClientError {
return error HeaderValidationStatusCodeClientError(reasonPhrase, cause, statusCode = statusCode, headers = headers, body = body, fromDefaultStatusCodeResponse = fromDefaultStatusCodeResponse);
return error HeaderValidationStatusCodeClientError(reasonPhrase, cause, statusCode = statusCode, headers = headers, body = body, fromDefaultStatusCodeMapping = fromDefaultStatusCodeMapping);
}
return error HeaderBindingStatusCodeClientError(reasonPhrase, cause, statusCode = statusCode, headers = headers, body = body, fromDefaultStatusCodeResponse = fromDefaultStatusCodeResponse);
return error HeaderBindingStatusCodeClientError(reasonPhrase, cause, statusCode = statusCode, headers = headers, body = body, fromDefaultStatusCodeMapping = fromDefaultStatusCodeMapping);
}
"mediaType" => {
if cause is MediaTypeValidationClientError {
return error MediaTypeValidationStatusCodeClientError(reasonPhrase, cause, statusCode = statusCode, headers = headers, body = body, fromDefaultStatusCodeResponse = fromDefaultStatusCodeResponse);
return error MediaTypeValidationStatusCodeClientError(reasonPhrase, cause, statusCode = statusCode, headers = headers, body = body, fromDefaultStatusCodeMapping = fromDefaultStatusCodeMapping);
}
return error MediaTypeBindingStatusCodeClientError(reasonPhrase, cause, statusCode = statusCode, headers = headers, body = body, fromDefaultStatusCodeResponse = fromDefaultStatusCodeResponse);
return error MediaTypeBindingStatusCodeClientError(reasonPhrase, cause, statusCode = statusCode, headers = headers, body = body, fromDefaultStatusCodeMapping = fromDefaultStatusCodeMapping);
}
"payload" => {
if cause is PayloadValidationClientError {
return error PayloadValidationStatusCodeClientError(reasonPhrase, cause, statusCode = statusCode, headers = headers, body = body, fromDefaultStatusCodeResponse = fromDefaultStatusCodeResponse);
return error PayloadValidationStatusCodeClientError(reasonPhrase, cause, statusCode = statusCode, headers = headers, body = body, fromDefaultStatusCodeMapping = fromDefaultStatusCodeMapping);
}
return error PayloadBindingStatusCodeClientError(reasonPhrase, cause, statusCode = statusCode, headers = headers, body = body, fromDefaultStatusCodeResponse = fromDefaultStatusCodeResponse);
return error PayloadBindingStatusCodeClientError(reasonPhrase, cause, statusCode = statusCode, headers = headers, body = body, fromDefaultStatusCodeMapping = fromDefaultStatusCodeMapping);
}
_ => {
return error StatusCodeResponseBindingError(reasonPhrase, cause, statusCode = statusCode, headers = headers, body = body, fromDefaultStatusCodeResponse = fromDefaultStatusCodeResponse);
return error StatusCodeResponseBindingError(reasonPhrase, cause, statusCode = statusCode, headers = headers, body = body, fromDefaultStatusCodeMapping = fromDefaultStatusCodeMapping);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions ballerina/http_errors.bal
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public type Detail record {

# Represents the details of an HTTP status code binding client error.
#
# + fromDefaultStatusCodeResponse - Indicates whether the error orginates from default status code response mapping
# + fromDefaultStatusCodeMapping - Indicates whether the error orginates from default status code response mapping
public type StatusCodeBindingErrorDetail record {
*Detail;
boolean fromDefaultStatusCodeResponse;
boolean fromDefaultStatusCodeMapping;
};

# Represents the details of the `LoadBalanceActionError`.
Expand Down
10 changes: 5 additions & 5 deletions ballerina/http_response.bal
Original file line number Diff line number Diff line change
Expand Up @@ -542,11 +542,11 @@ public class Response {

isolated function buildStatusCodeResponse(typedesc<anydata>? payloadType, typedesc<StatusCodeResponse> statusCodeResType,
boolean requireValidation, Status status, map<string|int|boolean|string[]|int[]|boolean[]> headers, string? mediaType,
boolean fromDefaultStatusCodeResponse) returns StatusCodeResponse|ClientError {
boolean fromDefaultStatusCodeMapping) returns StatusCodeResponse|ClientError {
if payloadType !is () {
anydata|ClientError payload = self.performDataBinding(payloadType, requireValidation);
if payload is ClientError {
return self.getStatusCodeResponseDataBindingError(payload.message(), fromDefaultStatusCodeResponse, "payload", payload);
return self.getStatusCodeResponseDataBindingError(payload.message(), fromDefaultStatusCodeMapping, "payload", payload);
}
return externBuildStatusCodeResponse(statusCodeResType, status, headers, payload, mediaType);
} else {
Expand Down Expand Up @@ -577,19 +577,19 @@ public class Response {
}
}

isolated function getStatusCodeResponseDataBindingError(string reasonPhrase, boolean fromDefaultStatusCodeResponse,
isolated function getStatusCodeResponseDataBindingError(string reasonPhrase, boolean fromDefaultStatusCodeMapping,
"header"|"mediaType"|"payload"|"generic" errorType, error? cause) returns ClientError {
map<string[]> headers = getHeaders(self);
anydata|error payload = getPayload(self);
int statusCode = self.statusCode;
if payload is error {
if payload is NoContentError {
return createStatusCodeResponseDataBindingError(errorType, fromDefaultStatusCodeResponse, statusCode, reasonPhrase, headers, cause = cause);
return createStatusCodeResponseDataBindingError(errorType, fromDefaultStatusCodeMapping, statusCode, reasonPhrase, headers, cause = cause);
}
return error PayloadBindingClientError("http:StatusCodeBindingError creation failed: " + statusCode.toString() +
" response payload extraction failed", payload);
} else {
return createStatusCodeResponseDataBindingError(errorType, fromDefaultStatusCodeResponse, statusCode, reasonPhrase, headers, payload, cause);
return createStatusCodeResponseDataBindingError(errorType, fromDefaultStatusCodeMapping, statusCode, reasonPhrase, headers, payload, cause);
}
}
}
Expand Down

0 comments on commit f6148d4

Please sign in to comment.