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

Returning a statusCode in a reply object causes unexpected error. #520

Closed
ssmereka opened this issue Sep 1, 2016 · 2 comments
Closed

Returning a statusCode in a reply object causes unexpected error. #520

ssmereka opened this issue Sep 1, 2016 · 2 comments
Assignees

Comments

@ssmereka
Copy link

ssmereka commented Sep 1, 2016

When returning the attribute statusCode in a seneca reply with an HTTP status code value representing an error (e.g. 401), seneca produces an error.

See the example below.

I'm not sure if this is expected behavior or not, but it was an unexpected result for me as a developer and took a bit to track down. To me, seneca should only produce an error if I return a value in the error parameter. Everything in the reply parameter should just be passed along.

Example Code:

Server.js

var seneca = require('seneca')();

seneca.add('role:my_role,cmd:my_cmd', (msg, reply) => {
  reply(undefined, { data: "ok", statusCode: 401 } );
})

seneca.ready(function() {
    seneca.listen({ type: 'http', pin: 'role:my_role' });
});

Server Output

Starting the server side.

ssmereka$ node server.js
{"kind":"notice","notice":"hello","level":"info","seneca":"vzfwu91dfmzz/1472758963286/97557/3.0.0/-","when":1472758963305}

Client.js

var seneca = require('seneca')();

seneca.ready(function() {
    seneca.client({ type: 'http', pin: 'role:my_role' });

    seneca.act({role: 'my_role', cmd: 'my_cmd'}, function (err, result) {
      console.log(err);     // error produced in seneca-transport/lib/transport-utils.js:70
      console.log(result);  // null
      console.log('Seneca Version: %s', this.version);
      console.log('Node Version: %s', process.version);
    });
});

Client Output

Starting the client side and acting on a pattern.

ssmereka$ node client.js
{"kind":"notice","notice":"hello","level":"info","seneca":"ny8e8o88sho4/1472758965532/97560/3.0.0/-","when":1472758965551}
{"notice":"seneca: Action role:my_role failed: .","code":"act_execute","err":{"data":"ok","statusCode":401,"eraro":true,"orig":{"data":"ok","statusCode":401},"code":"act_execute","seneca":true,"package":"seneca","msg":"seneca: Action role:my_role failed: .","details":{"message":"","pattern":"role:my_role","instance":"Seneca/ny8e8o88sho4/1472758965532/97560/3.0.0/-","orig$":{"data":"ok","statusCode":401},"message$":"","plugin":{}},"callpoint":"at internals.Utils.handle_response (/Users/ssmereka/Documents/temp/seneca/node_modules/seneca-transport/lib/transport-utils.js:70:11)"},"actid":"62h9yigi0e5t/w25o63gxtzox","msg":{"role":"my_role","cmd":"my_cmd","meta$":{"id":"62h9yigi0e5t/w25o63gxtzox","tx":"w25o63gxtzox","start":1472758965630,"pattern":"role:my_role","action":"(ansmesl31io0)","entry":true,"chain":[],"sync":true,"plugin_name":"client$","plugin_tag":"-"},"plugin$":{"name":"client$","tag":"-"},"tx$":"w25o63gxtzox"},"entry":true,"prior":[],"meta":{"plugin_name":"client$","plugin_tag":"-","plugin_fullname":"client$","raw":{"role":"my_role","client$":true,"internal$":{"catchall":true}},"sub":false,"client":true,"args":{"role":"my_role"},"rules":{},"id":"(ansmesl31io0)","pattern":"role:my_role","msgcanon":{"role":"my_role"},"priorpath":""},"client":true,"listen":false,"transport":{},"kind":"act","case":"ERR","duration":41,"level":"error","seneca":"ny8e8o88sho4/1472758965532/97560/3.0.0/-","when":1472758965674}
{ Error
    at internals.Utils.handle_response (/Users/ssmereka/Documents/temp/seneca/node_modules/seneca-transport/lib/transport-utils.js:70:11)
    at /Users/ssmereka/Documents/temp/seneca/node_modules/seneca-transport/lib/http.js:148:25
    at read (/Users/ssmereka/Documents/temp/seneca/node_modules/wreck/lib/index.js:514:20)
    at finish (/Users/ssmereka/Documents/temp/seneca/node_modules/wreck/lib/index.js:360:16)
    at wrapped (/Users/ssmereka/Documents/temp/seneca/node_modules/hoek/lib/index.js:871:20)
    at onReaderFinish (/Users/ssmereka/Documents/temp/seneca/node_modules/wreck/lib/index.js:406:16)
    at g (events.js:286:16)
    at emitNone (events.js:91:20)
    at emit (events.js:185:7)
    at finishMaybe (_stream_writable.js:488:14)
  data: 'ok',
  statusCode: 401,
  eraro: true,
  orig:
   { Error
       at internals.Utils.handle_response (/Users/ssmereka/Documents/temp/seneca/node_modules/seneca-transport/lib/transport-utils.js:70:11)
       at /Users/ssmereka/Documents/temp/seneca/node_modules/seneca-transport/lib/http.js:148:25
       at read (/Users/ssmereka/Documents/temp/seneca/node_modules/wreck/lib/index.js:514:20)
       at finish (/Users/ssmereka/Documents/temp/seneca/node_modules/wreck/lib/index.js:360:16)
       at wrapped (/Users/ssmereka/Documents/temp/seneca/node_modules/hoek/lib/index.js:871:20)
       at onReaderFinish (/Users/ssmereka/Documents/temp/seneca/node_modules/wreck/lib/index.js:406:16)
       at g (events.js:286:16)
       at emitNone (events.js:91:20)
       at emit (events.js:185:7)
       at finishMaybe (_stream_writable.js:488:14) data: 'ok', statusCode: 401 },
  code: 'act_execute',
  seneca: true,
  package: 'seneca',
  msg: 'seneca: Action role:my_role failed: .',
  details:
   { message: '',
     pattern: 'role:my_role',
     fn: { [Function: transport_client] id: 'pg:role:my_role,pin:role:my_role,type:http' },
     cb: [Function],
     instance: 'Seneca/ny8e8o88sho4/1472758965532/97560/3.0.0/-',
     'orig$':
      { Error
          at internals.Utils.handle_response (/Users/ssmereka/Documents/temp/seneca/node_modules/seneca-transport/lib/transport-utils.js:70:11)
          at /Users/ssmereka/Documents/temp/seneca/node_modules/seneca-transport/lib/http.js:148:25
          at read (/Users/ssmereka/Documents/temp/seneca/node_modules/wreck/lib/index.js:514:20)
          at finish (/Users/ssmereka/Documents/temp/seneca/node_modules/wreck/lib/index.js:360:16)
          at wrapped (/Users/ssmereka/Documents/temp/seneca/node_modules/hoek/lib/index.js:871:20)
          at onReaderFinish (/Users/ssmereka/Documents/temp/seneca/node_modules/wreck/lib/index.js:406:16)
          at g (events.js:286:16)
          at emitNone (events.js:91:20)
          at emit (events.js:185:7)
          at finishMaybe (_stream_writable.js:488:14) data: 'ok', statusCode: 401 },
     'message$': '',
     plugin: {} },
  callpoint: 'at internals.Utils.handle_response (/Users/ssmereka/Documents/temp/seneca/node_modules/seneca-transport/lib/transport-utils.js:70:11)' }
null
Seneca Version: 3.0.0
Node Version: v6.2.0
@ssmereka
Copy link
Author

@mcdonnelldean bumping the issue.

Is this an error or expected behavior?

@rjrodger
Copy link
Collaborator

this is a seneca-transport issue: senecajs/seneca-transport#154

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

No branches or pull requests

3 participants