Skip to content

Commit

Permalink
Address review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
dulajdilshan committed Jun 28, 2024
1 parent db0b569 commit 281dbfd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5686,7 +5686,6 @@ private BErrorType createErrorType(BType lhsType, BType rhsType, BType detailTyp
BErrorType rhsErrorType = (BErrorType) rhsType;

long flags = lhsType.flags | rhsType.flags | Flags.PUBLIC; // Anonymous error intersection types must be public

BErrorType errorType = createErrorType(detailType, flags, env);

errorType.typeIdSet = BTypeIdSet.getIntersection(lhsErrorType.typeIdSet, rhsErrorType.typeIdSet);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,42 @@

import error_intersection_access.error_intersection_mod as err_lib;

function testErrorIntersectionAccessTest(int code) returns error? {
string reason = "response error";
public function testErrorIntersectionAccessTest() {
err_lib:RemoteServerError remoteServerErr = error err_lib:RemoteServerError("remote server error");
assertEquality("remote server error", remoteServerErr.message());

if code > 500 {
return error err_lib:RemoteServerError(reason);
}
err_lib:ApplicationResponseError applResponeErr = error err_lib:ApplicationResponseError("application response server error");
assertEquality("application response server error", applResponeErr.message());

if code == 500 {
return error err_lib:ApplicationResponseError(reason);
}
err_lib:ClientRequestErrorWithStatusCode clientReqErrWithStatusCode =
error err_lib:ClientRequestErrorWithStatusCode("client request error", code = 404);
assertEquality("client request error", clientReqErrWithStatusCode.message());
assertEquality(404, clientReqErrWithStatusCode.detail().code);

err_lib:ApplicationResponseErrorWithStatusCode applResponseErrWithStatusCode =
error err_lib:ApplicationResponseErrorWithStatusCode("application response error", code = 401);
assertEquality("application response error", applResponseErrWithStatusCode.message());
assertEquality(401, applResponseErrWithStatusCode.detail().code);

if code > 400 {
if code == 404 {
return error err_lib:ClientRequestErrorWithStatusCode(reason, code = code);
}
err_lib:BadRequestError badReqErr = error err_lib:BadRequestError("bad request error", code = 400);
assertEquality("bad request error", badReqErr);
assertEquality(400, badReqErr.detail().code);

err_lib:Error err = error err_lib:Error("response error");
assertEquality("error", err.message());
}

return error err_lib:ApplicationResponseErrorWithStatusCode(reason, code = code);
function assertEquality(any|error actual, any|error expected) {
if expected is anydata && actual is anydata && expected == actual {
return;
}

if code == 400 {
return error err_lib:BadRequestError(reason, code = 0);
if expected === actual {
return;
}

return error err_lib:Error(reason);
string expectedValAsString = expected is error ? expected.toString() : expected.toString();
string actualValAsString = actual is error ? actual.toString() : actual.toString();
panic error("AssertionError",
message = "expected '" + expectedValAsString + "', found '" + actualValAsString + "'");
}

0 comments on commit 281dbfd

Please sign in to comment.