Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Before filter controller support break next performance handlers #157

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Orel2888
Copy link

// Support filter return false 
class PingController extends TelegramBaseController {

	before(scope) {

        return false
    }

    pingHandler($) {
    	return $.sendMessage('Pong')
    }

    /**
    * Run if before returned false
    */
    rejected(err, $) {

    	return $.sendMessage('Before filter returned false')
    }

	get routes() {
        return {
            'pingCommand': 'pingHandler'
        }
    }
}


// Support filter return {Promise}. Use resolve
class PingController extends TelegramBaseController {

	before(scope) {

        return new Promise((resolve, reject) => {
        	scope.someKey = 'data'

        	resolve(scope)
        })
    }

    pingHandler($) {
    	return $.sendMessage('Pong')
    }

	get routes() {
        return {
            'pingCommand': 'pingHandler'
        }
    }
}

// Support filter return {Promise}. Use reject
class PingController extends TelegramBaseController {

	before(scope) {

        return new Promise((resolve, reject) => {
        	
        	reject('Error')
        })
    }

    pingHandler($) {
    	return $.sendMessage('Pong')
    }


	/**
    * Catch error from before
    */    
    rejected(err, $) {

    	return $.sendMessage('Rejected', err)
    }

	get routes() {
        return {
            'pingCommand': 'pingHandler'
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant