Skip to content

Commit

Permalink
Merge pull request #171 from lahirulakruwan/main
Browse files Browse the repository at this point in the history
Api Response error messages changes added
  • Loading branch information
YujithIsura authored Oct 7, 2024
2 parents 566d38f + 39038c2 commit 266cb5a
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions api/main.bal
Original file line number Diff line number Diff line change
Expand Up @@ -5564,6 +5564,8 @@ AND p.organization_id IN (
int|string? permanent_address_insert_id = null;
int|string? mailing_address_insert_id = null;

string message = "";

transaction {

int permanent_address_id = permanent_address?.id ?: 0;
Expand Down Expand Up @@ -5591,6 +5593,7 @@ AND p.organization_id IN (
if (permanent_address_res.affectedRowCount == sql:EXECUTION_FAILED) {
first_db_transaction_fail = true;
io:println("Unable to update permanent address record");
message = "Unable to update permanent address record";
}
}

Expand All @@ -5616,6 +5619,7 @@ AND p.organization_id IN (
if !(permanent_address_insert_id is int) {
first_db_transaction_fail = true;
io:println("Unable to insert permanent address");
message = "Unable to insert permanent address";
}
}
}
Expand Down Expand Up @@ -5646,6 +5650,7 @@ AND p.organization_id IN (
if (mailing_address_res.affectedRowCount == sql:EXECUTION_FAILED) {
second_db_transaction_fail = true;
io:println("Unable to update mailing address record");
message = "Unable to update mailing address record";
}
}

Expand All @@ -5670,6 +5675,7 @@ AND p.organization_id IN (
if !(mailing_address_insert_id is int) {
second_db_transaction_fail = true;
io:println("Unable to insert mailing address");
message = "Unable to insert mailing address";
}
}

Expand Down Expand Up @@ -5711,14 +5717,15 @@ AND p.organization_id IN (
if (update_person_res.affectedRowCount == sql:EXECUTION_FAILED) {
third_db_transaction_fail = true;
io:println("Unable to update person record");
message = "Unable to update person record";
}

if (first_db_transaction_fail ||
second_db_transaction_fail ||
third_db_transaction_fail) {

rollback;
return error("Transaction rollback");
return error(message);
} else {

// Commit the transaction if three updates are successful
Expand All @@ -5739,6 +5746,7 @@ AND p.organization_id IN (

int|string? mailing_address_insert_id = null;

string message = "";

transaction {

Expand All @@ -5752,6 +5760,7 @@ AND p.organization_id IN (
if (personRaw is Person) {
first_db_transaction_fail = true;
io:println("Person already exists.");
message="Person already exists.";
}


Expand All @@ -5774,6 +5783,7 @@ AND p.organization_id IN (
if !(mailing_address_insert_id is int) {
second_db_transaction_fail = true;
io:println("Unable to insert mailing address");
message = "Unable to insert mailing address";
}
}

Expand Down Expand Up @@ -5829,14 +5839,15 @@ AND p.organization_id IN (
if !(insert_person_id is int) {
third_db_transaction_fail = true;
io:println("Unable to insert person");
message = "Unable to insert person";
}

if (first_db_transaction_fail ||
second_db_transaction_fail ||
third_db_transaction_fail) {

rollback;
return error("Transaction rollback");
return error(message);
} else {

// Commit the transaction if three updates are successful
Expand Down

0 comments on commit 266cb5a

Please sign in to comment.