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

A problem with processing array responses with workerResponseHandlers #38

Open
killmenot opened this issue May 17, 2019 · 0 comments
Open

Comments

@killmenot
Copy link

Hi @robtweed

Just a note for you. I believe you may know about this problem and know what to do (if it's needed ofc)

We just have found a "problem" with processing array responses with microservices logic that related with

  • qewd
  • qewd-router

Related snippets of code
(1): https://github.com/robtweed/qewd/blob/master/lib/appHandler.js#L464-L478
(2): https://github.com/robtweed/qewd-router/blob/master/lib/router.js#L223-L226

Scenario 1 - object response: (problem is not reproduced)

When object response returned it goes to (2) and path is set correctly
Example:

{
  foo: 'bar'
  path: '/api/test'
}

Scenario 2 - array response:

When array response returned it goes to (2) and path is set the following way
Example:

[
 {
   foo: 'bar1'
 },
 {
   foo: 'bar2'
 },
 path: '/api/test'
]

Only after that, the logic goes to (1) to line 469
if (messageObj.ms_requestId && Array.isArray(results)) results = {results: results};

This problem appears with worker response logic because there is no path in messageObj:

if (workerResponseHandler[message.path]) {

HOW TO FIX IT

The quick solution is to use your pattern when you return array response the following way:

{
api: 'getRespectFormVersions',
use: 'results',
results: [
{
foo: 'bar1'
},
{
foo: 'bar2'
},
]
}

However, I believe that it's better to patch qewd-router (2) to process array responses correctly there

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

No branches or pull requests

1 participant