Skip to content

A problem with processing array responses with workerResponseHandlers #38

@killmenot

Description

@killmenot

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions