Switch case where I want to do some things if case A OR B and other things if case A XOR B?

Look at this switch case statement. Cases 'response' and 'error' have a lot in common, but also one line that tells them apart.

            switch (data.type) {
                case 'response':
                    const transactionId = data.trans_id;
                    const callbacks = commandCallbacks[transactionId];
                if (!callbacks) {
                    if (logger) logger(`Dropping received message that was not requested, transactionId: ${transactionId}`);
                    break;
                }

                clearTimeout(callbacks.timedOutTimer);
                callbacks.resolver(data);
                break;
            case 'error':                
                const transactionId = data.trans_id;
                const callbacks = commandCallbacks[transactionId];

                if (!callbacks) {
                    if (logger) logger(`Dropping received message that was not requested, transactionId: ${transactionId}`);
                    break;
                }

                clearTimeout(callbacks.timedOutTimer);
                callbacks.rejecter(data);
                break;
            case 'information':
            case 'progress':
            default:
                break;
        }

How can I simplify this code?

#javascript

1 Likes1.65 GEEK