Skip to content

Commit

Permalink
Merge pull request #1651 from dilanSachi/make-status-code-private
Browse files Browse the repository at this point in the history
Move status code errors to `httpscerr` module
  • Loading branch information
TharmiganK authored Jun 15, 2023
2 parents 8304d9a + 059b478 commit bdabc88
Show file tree
Hide file tree
Showing 23 changed files with 547 additions and 477 deletions.
3 changes: 2 additions & 1 deletion ballerina-tests/http-advanced-tests/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ dependencies = [
{org = "ballerina", name = "url"}
]
modules = [
{org = "ballerina", packageName = "http", moduleName = "http"}
{org = "ballerina", packageName = "http", moduleName = "http"},
{org = "ballerina", packageName = "http", moduleName = "http.status_errors"}
]

[[package]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,127 +15,128 @@
// under the License.

import ballerina/http;
import ballerina/http.httpscerr;
import ballerina/test;
import ballerina/http_test_common as common;

function getStatusCodeError(int statusCode) returns http:StatusCodeError {
function getStatusCodeError(int statusCode) returns httpscerr:StatusCodeError {
match statusCode {
400 => {
return error http:BadRequestError("Bad request error");
return error httpscerr:BadRequestError("Bad request error");
}
401 => {
return error http:UnauthorizedError("Unauthorized error");
return error httpscerr:UnauthorizedError("Unauthorized error");
}
402 => {
return error http:PaymentRequiredError("Payment required error");
return error httpscerr:PaymentRequiredError("Payment required error");
}
403 => {
return error http:ForbiddenError("Forbidden error");
return error httpscerr:ForbiddenError("Forbidden error");
}
404 => {
return error http:NotFoundError("Not found error");
return error httpscerr:NotFoundError("Not found error");
}
405 => {
return error http:MethodNotAllowedError("Method not allowed error");
return error httpscerr:MethodNotAllowedError("Method not allowed error");
}
406 => {
return error http:NotAcceptableError("Not acceptable error");
return error httpscerr:NotAcceptableError("Not acceptable error");
}
407 => {
return error http:ProxyAuthenticationRequiredError("Proxy authentication required error");
return error httpscerr:ProxyAuthenticationRequiredError("Proxy authentication required error");
}
408 => {
return error http:RequestTimeoutError("Request timeout error");
return error httpscerr:RequestTimeoutError("Request timeout error");
}
409 => {
return error http:ConflictError("Conflict error");
return error httpscerr:ConflictError("Conflict error");
}
410 => {
return error http:GoneError("Gone error");
return error httpscerr:GoneError("Gone error");
}
411 => {
return error http:LengthRequiredError("Length required error");
return error httpscerr:LengthRequiredError("Length required error");
}
412 => {
return error http:PreconditionFailedError("Precondition failed error");
return error httpscerr:PreconditionFailedError("Precondition failed error");
}
413 => {
return error http:PayloadTooLargeError("Payload too large error");
return error httpscerr:PayloadTooLargeError("Payload too large error");
}
414 => {
return error http:URITooLongError("URI too long error");
return error httpscerr:URITooLongError("URI too long error");
}
415 => {
return error http:UnsupportedMediaTypeError("Unsupported media type error");
return error httpscerr:UnsupportedMediaTypeError("Unsupported media type error");
}
416 => {
return error http:RangeNotSatisfiableError("Range not satisfiable error");
return error httpscerr:RangeNotSatisfiableError("Range not satisfiable error");
}
417 => {
return error http:ExpectationFailedError("Expectation failed error");
return error httpscerr:ExpectationFailedError("Expectation failed error");
}
421 => {
return error http:MisdirectedRequestError("Misdirected request error");
return error httpscerr:MisdirectedRequestError("Misdirected request error");
}
422 => {
return error http:UnprocessableEntityError("Unprocessable entity error");
return error httpscerr:UnprocessableEntityError("Unprocessable entity error");
}
423 => {
return error http:LockedError("Locked error");
return error httpscerr:LockedError("Locked error");
}
424 => {
return error http:FailedDependencyError("Failed dependency error");
return error httpscerr:FailedDependencyError("Failed dependency error");
}
426 => {
return error http:UpgradeRequiredError("Upgrade required error");
return error httpscerr:UpgradeRequiredError("Upgrade required error");
}
428 => {
return error http:PreconditionRequiredError("Precondition required error");
return error httpscerr:PreconditionRequiredError("Precondition required error");
}
429 => {
return error http:TooManyRequestsError("Too many requests error");
return error httpscerr:TooManyRequestsError("Too many requests error");
}
431 => {
return error http:RequestHeaderFieldsTooLargeError("Request header fields too large error");
return error httpscerr:RequestHeaderFieldsTooLargeError("Request header fields too large error");
}
451 => {
return error http:UnavailableDueToLegalReasonsError("Unavailable for legal reasons error");
return error httpscerr:UnavailableDueToLegalReasonsError("Unavailable for legal reasons error");
}
500 => {
return error http:InternalServerErrorError("Internal server error error");
return error httpscerr:InternalServerErrorError("Internal server error error");
}
501 => {
return error http:NotImplementedError("Not implemented error");
return error httpscerr:NotImplementedError("Not implemented error");
}
502 => {
return error http:BadGatewayError("Bad gateway error");
return error httpscerr:BadGatewayError("Bad gateway error");
}
503 => {
return error http:ServiceUnavailableError("Service unavailable error");
return error httpscerr:ServiceUnavailableError("Service unavailable error");
}
504 => {
return error http:GatewayTimeoutError("Gateway timeout error");
return error httpscerr:GatewayTimeoutError("Gateway timeout error");
}
505 => {
return error http:HTTPVersionNotSupportedError("HTTP version not supported error");
return error httpscerr:HTTPVersionNotSupportedError("HTTP version not supported error");
}
506 => {
return error http:VariantAlsoNegotiatesError("Variant also negotiates error");
return error httpscerr:VariantAlsoNegotiatesError("Variant also negotiates error");
}
507 => {
return error http:InsufficientStorageError("Insufficient storage error");
return error httpscerr:InsufficientStorageError("Insufficient storage error");
}
508 => {
return error http:LoopDetectedError("Loop detected error");
return error httpscerr:LoopDetectedError("Loop detected error");
}
510 => {
return error http:NotExtendedError("Not extended error");
return error httpscerr:NotExtendedError("Not extended error");
}
511 => {
return error http:NetworkAuthenticationRequiredError("Network authentication required error");
return error httpscerr:NetworkAuthenticationRequiredError("Network authentication required error");
}
_ => {
return error http:DefaultStatusCodeError("Default error", statusCode = statusCode);
return error httpscerr:DefaultStatusCodeError("Default error", statusCode = statusCode);
}
}
}
Expand All @@ -147,19 +148,19 @@ type CustomHeaders record {|

service on new http:Listener(statusCodeErrorPort) {

resource function get statusCodeError(int statusCode) returns http:StatusCodeError {
resource function get statusCodeError(int statusCode) returns httpscerr:StatusCodeError {
return getStatusCodeError(statusCode);
}

resource function get statusCodeErrorWithCause(int statusCode) returns http:DefaultStatusCodeError {
resource function get statusCodeErrorWithCause(int statusCode) returns httpscerr:DefaultStatusCodeError {
error err = statusCode == 0 ? error("New error") : getStatusCodeError(statusCode);
return error http:DefaultStatusCodeError("Default error", err);
return error httpscerr:DefaultStatusCodeError("Default error", err);
}

resource function post statusCodeError(@http:Payload anydata payload, int statusCode,
@http:Header CustomHeaders headers) returns http:StatusCodeError {
@http:Header CustomHeaders headers) returns httpscerr:StatusCodeError {

return error http:DefaultStatusCodeError("Default error", statusCode = statusCode,
return error httpscerr:DefaultStatusCodeError("Default error", statusCode = statusCode,
body = payload, headers = headers);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// under the License.

import ballerina/http;
import ballerina/http.httpscerr;
import ballerina/time;
import ballerina/test;

Expand All @@ -27,15 +28,15 @@ type ErrorInfo record {|
|};

type ErrorDetails record {|
*http:ErrorDetail;
*httpscerr:ErrorDetail;
ErrorInfo body;
|};

type UserNotFoundError Error & http:NotFoundError & error<ErrorDetails>;
type UserNotFoundError Error & httpscerr:NotFoundError & error<ErrorDetails>;

type UserNameAlreadyExistError Error & http:ConflictError & error<ErrorDetails>;
type UserNameAlreadyExistError Error & httpscerr:ConflictError & error<ErrorDetails>;

type BadUserError Error & http:BadRequestError & error<ErrorDetails>;
type BadUserError Error & httpscerr:BadRequestError & error<ErrorDetails>;

type User record {|
readonly int id;
Expand Down Expand Up @@ -116,9 +117,9 @@ service on new http:Listener(statusCodeErrorUseCasePort) {
return addUser(user);
}

resource function 'default [string... path]() returns http:NotFoundError {
resource function 'default [string... path]() returns httpscerr:NotFoundError {

return error http:NotFoundError("Resource not found", body = {
return error httpscerr:NotFoundError("Resource not found", body = {
timeStamp: getCurrentTimeStamp(),
message: string `Resource not found for path: /${string:'join("/", ...path)}`
});
Expand Down
3 changes: 2 additions & 1 deletion ballerina-tests/http-client-tests/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ dependencies = [
{org = "ballerina", name = "url"}
]
modules = [
{org = "ballerina", packageName = "http", moduleName = "http"}
{org = "ballerina", packageName = "http", moduleName = "http"},
{org = "ballerina", packageName = "http", moduleName = "http.httpscerr"}
]

[[package]]
Expand Down
3 changes: 2 additions & 1 deletion ballerina-tests/http-dispatching-tests/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ dependencies = [
{org = "ballerina", name = "url"}
]
modules = [
{org = "ballerina", packageName = "http", moduleName = "http"}
{org = "ballerina", packageName = "http", moduleName = "http"},
{org = "ballerina", packageName = "http", moduleName = "http.httpscerr"}
]

[[package]]
Expand Down
3 changes: 2 additions & 1 deletion ballerina-tests/http-interceptor-tests/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ dependencies = [
{org = "ballerina", name = "url"}
]
modules = [
{org = "ballerina", packageName = "http", moduleName = "http"}
{org = "ballerina", packageName = "http", moduleName = "http"},
{org = "ballerina", packageName = "http", moduleName = "http.httpscerr"}
]

[[package]]
Expand Down
3 changes: 2 additions & 1 deletion ballerina-tests/http-misc-tests/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ dependencies = [
{org = "ballerina", name = "url"}
]
modules = [
{org = "ballerina", packageName = "http", moduleName = "http"}
{org = "ballerina", packageName = "http", moduleName = "http"},
{org = "ballerina", packageName = "http", moduleName = "http.httpscerr"}
]

[[package]]
Expand Down
3 changes: 2 additions & 1 deletion ballerina-tests/http-security-tests/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ dependencies = [
{org = "ballerina", name = "url"}
]
modules = [
{org = "ballerina", packageName = "http", moduleName = "http"}
{org = "ballerina", packageName = "http", moduleName = "http"},
{org = "ballerina", packageName = "http", moduleName = "http.httpscerr"}
]

[[package]]
Expand Down
3 changes: 2 additions & 1 deletion ballerina-tests/http-service-tests/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ dependencies = [
{org = "ballerina", name = "url"}
]
modules = [
{org = "ballerina", packageName = "http", moduleName = "http"}
{org = "ballerina", packageName = "http", moduleName = "http"},
{org = "ballerina", packageName = "http", moduleName = "http.httpscerr"}
]

[[package]]
Expand Down
3 changes: 2 additions & 1 deletion ballerina-tests/http2-tests/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ dependencies = [
{org = "ballerina", name = "url"}
]
modules = [
{org = "ballerina", packageName = "http", moduleName = "http"}
{org = "ballerina", packageName = "http", moduleName = "http"},
{org = "ballerina", packageName = "http", moduleName = "http.httpscerr"}
]

[[package]]
Expand Down
1 change: 1 addition & 0 deletions ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ repository = "https://github.com/ballerina-platform/module-ballerina-http"
icon = "icon.png"
license = ["Apache-2.0"]
distribution = "2201.5.0"
export = ["http", "http.httpscerr"]

[[platform.java11.dependency]]
groupId = "io.ballerina.stdlib"
Expand Down
3 changes: 2 additions & 1 deletion ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ dependencies = [
{org = "ballerina", name = "url"}
]
modules = [
{org = "ballerina", packageName = "http", moduleName = "http"}
{org = "ballerina", packageName = "http", moduleName = "http"},
{org = "ballerina", packageName = "http", moduleName = "http.httpscerr"}
]

[[package]]
Expand Down
3 changes: 2 additions & 1 deletion ballerina/http_connection.bal
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import ballerina/lang.value as val;
import ballerina/lang.'string as strings;
import ballerina/url;
import ballerina/mime;
import http.httpscerr;

# The caller actions for responding to client requests.
#
Expand Down Expand Up @@ -194,7 +195,7 @@ public isolated client class Caller {
private isolated function returnErrorResponse(error errorResponse, string? returnMediaType = ()) returns ListenerError? {
error err = errorResponse;
if errorResponse is ClientConnectorError {
err = error BadGatewayError(getClientConnectorErrorCause(errorResponse));
err = error httpscerr:BadGatewayError(getClientConnectorErrorCause(errorResponse));
}
return nativeRespondError(self, getErrorResponse(errorResponse, returnMediaType), err);
}
Expand Down
Loading

0 comments on commit bdabc88

Please sign in to comment.