js-bigchaindb-driver icon indicating copy to clipboard operation
js-bigchaindb-driver copied to clipboard

how to emit '403 Forbidden' to UI

Open srinivasyl opened this issue 7 years ago • 2 comments

var driver = require('bigchaindb-driver')

var alice = new driver.Ed25519Keypair()
var conn = new driver.Connection(
    'https://test.bigchaindb.com/api/v1/',
    { app_id: 'my_app_id',
      app_key: 'wrong key' })

var tx = driver.Transaction.makeCreateTransaction(
    { city: 'Bangalore', temperature: 22, location:'Winjit Bangalore', datetime: new Date().toString() },
    null,
    [ driver.Transaction.makeOutput(
        driver.Transaction.makeEd25519Condition(alice.publicKey))],
    alice.publicKey)

var txSigned = driver.Transaction.signTransaction(tx, alice.privateKey)

conn.postTransactionCommit(txSigned).then(function(retrievedTx){
		if(retrievedTx){
			console.log('Transaction', retrievedTx.id, 'successfully posted.')	
		}
});

if wrong API key is given it gives below erro how to emit this to UI what condition should i check to this error

{ message: 'HTTP Error: Requested page not reachable', status: '403 Forbidden', requestURI: 'https://test.bigchaindb.com/api/v1/transactions?mode=commit' }

srinivasyl avatar Sep 11 '18 09:09 srinivasyl

You can use:

      conn.postTransactionCommit(createTranfer)
        .then(res => {
            //...
        })
        .catch(err => {
           if(err.status == '403 Forbidden')
        })

See also #169

future-is-present avatar Sep 17 '18 09:09 future-is-present

Thank you it got sorted i used

conn.postTransactionCommit(txSigned).then(function(retrievedTx){
			console.log('Transaction', retrievedTx.id, 'successfully posted.')	
},function(err){
	console.log(err)
});

srinivasyl avatar Sep 17 '18 10:09 srinivasyl