Hyperledger Composer REST Server transaction failed but returns 200 status

0 votes

I have written a transaction to make Hyperledger Composer REST server to return a 500 error code when a transaction fails, but even when transaction fails, returns 200.

Here is the transaction:

/**
 * Move a player totem
 * @param {org.pandemic.board.MoveTotem} txData
 * @transaction
 */
function moveTotem(txData) {
    let moveType = txData.moveType;
    let boardId = txData.boardId;
    let totemName = txData.totemName;
    let destination = txData.destination;

    switch(moveType) {
        case "DRIVE_FERRY":
            driveFerry(boardId, totemName, destination);
            break;
        case "DIRECT_FLIGHT":
            directFlight(boardId, totemName, destination);
            break;
        case "CHARTER_FLIGHT":
            charterFlight(boardId, totemName, destination);
            break;
        case "SHUTTLE_FLIGHT":
            shuttleFlight(boardId, totemName, destination);
            break;
        default:
            throw new Error("Invalid move type specified");
    }
}

And specifically the first case statement:

function driveFerry(boardId, totemName, destination) {
    return getAssetRegistry('org.pandemic.board.Board').then((registry) => {

        return registry.get(boardId).then((board) => {
            let playerIdx = getPlayerTotemIdx(board, totemName);

            checkRemainingActions(board, playerIdx);

            let currentBoardCity = getCurrentBoardCityForPlayer(board, playerIdx);

            if(currentBoardCity == null || currentBoardCity.length == 0) {
                throw new Error("Player is not in a city, how did that happen? Ending game...");
                //TODO: end the game
            }

            if(currentBoardCity.connections.indexOf(destination) > -1) {
                board.players[playerIdx].currentLocation = destination;
                board.players[playerIdx].actionsRemaining -= 1;
                return registry.update(board);
            } else {
                return Promise.reject("Destination is not connected to current city");
               //throw new Error();
            }

        });
    });
}

Nov 6, 2018 in Blockchain by digger
• 26,740 points
848 views

1 answer to this question.

0 votes

You need to return the function calls from the initial switch statement in the transaction code, like this:

/**
 * Move a player totem
 * @param {org.pandemic.board.MoveTotem} txData
 * @transaction
 */
function moveTotem(txData) {
    let moveType = txData.moveType;
    let boardId = txData.boardId;
    let totemName = txData.totemName;
    let destination = txData.destination;

    switch(moveType) {
        case "DRIVE_FERRY":
            return driveFerry(boardId, totemName, destination);
        case "DIRECT_FLIGHT":
            return directFlight(boardId, totemName, destination);
        case "CHARTER_FLIGHT":
            return charterFlight(boardId, totemName, destination);
        case "SHUTTLE_FLIGHT":
            return shuttleFlight(boardId, totemName, destination);
    }
}
answered Nov 6, 2018 by Omkar
• 69,220 points

Related Questions In Blockchain

0 votes
1 answer

Hyperledger Composer rest server NPM versions

The Hyperledger Composer pre-requisites can be installed ...READ MORE

answered Jul 13, 2018 in Blockchain by Christine
• 15,790 points
858 views
0 votes
1 answer

Why hyperledger REST server has PUT method?

Actually, with the PUT method, you don't ...READ MORE

answered Jul 19, 2018 in Blockchain by aryya
• 7,460 points
590 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,463 views
+1 vote
1 answer

I am unable to change port of composer-rest-server. Please help!

Use full format for running a business ...READ MORE

answered Mar 27, 2018 in Blockchain by Christine
• 15,790 points
1,143 views
+1 vote
1 answer
0 votes
1 answer

HyperLedger Composer: Failed to load connector module “composer-connector-embedded” for connection profile “testprofile”

First, update your devDependencies in package.json "devDependencies": { ... "composer-admin": ...READ MORE

answered Nov 2, 2018 in Blockchain by Omkar
• 69,220 points
784 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP