Sha256: fa0f428a07cdc0703376ffb76d4f03c0128b5964e2bfd1a0a9e9e2e87d6db96b

Contents?: true

Size: 1.11 KB

Versions: 2

Compression:

Stored size: 1.11 KB

Contents

const AbstractHandler = require('./AbstractHandler')

class GetInstanceFieldHandler extends AbstractHandler {
    requiredParametersCount = 2

    constructor() {
        super()
    }

    process(command) {
        try {
            if (command.payload.length < this.requiredParametersCount) {
                throw new Error('Get Instance Field parameters mismatch')
            }
            const { payload } = command
            let instance = payload[0]
            let field = payload[1]
            let instanceField = instance[field]
            if (typeof instanceField === 'undefined') {
                let fields = Object.keys(instance)
                let message = `Field ${field} not found in object. Available fields:\n`
                fields.forEach((fieldIter) => {
                    message += `${fieldIter}\n`
                })
                throw new Error(message)
            } else {
                return instanceField
            }
        } catch (error) {
            throw this.process_stack_trace(error, this.constructor.name)
        }
    }
}

module.exports = new GetInstanceFieldHandler()

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
javonet-ruby-sdk-2.5.10 lib/javonet-ruby-sdk/Binaries/Nodejs/lib/core/handler/GetInstanceFieldHandler.js
javonet-ruby-sdk-2.5.9 lib/javonet-ruby-sdk/Binaries/Nodejs/lib/core/handler/GetInstanceFieldHandler.js