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

When doing stream processing, how to solve Error: Cannot return null or undefined from an endpoint: #277

Open
gurjit03 opened this issue May 25, 2017 · 5 comments

Comments

@gurjit03
Copy link

gurjit03 commented May 25, 2017

I am in need to do processing of stream where I need to convert my pdf data to base64 encoded string to be send to the client on his request.

Function to get pdf data

function getPdfData(rdData,url) {
     let pdfData = '';
     const doBufferProcessing = function(buffer){
       let part = buffer.toString();
       pdfData += part;
       // console.log(pdfData,"pdfData");
     }

         base64stream
           .on('data',doBufferProcessing)
           .on('end',() => {
             return {
                data : pdfData
              }
           });
}

API endpoint

Api.addRoute('get-pdf',{authRequired : true},{
  post : function() {
    let bodyParams  = this.bodyParams;
    let url = bodyParams.url;
   
       const getPdfDataPrWrapper = () => {
        return new Promise((resolve,reject) => {
          let value = getPdfData(rdData, url);
          if(value) {
            resolve(value)
          }else {
            reject("error")
          }
        })
      }

      getPdfDataPrWrapper()
      .then(response => {
        console.log(response, "from the rdAnnotate Data");
        return {
          status : 'success',
          statusCode : 200,
          pdfData : response.pdfData,
          data : {
            message : "yes pdf data is return"
          }
        }
      })
      .catch(e => {
        console.log(e,"error from the rdAnnotate")
        return {
          status : 'error',
          statusCode : 500,
          data : {
            message : e
          }
        }
      })
    }
    else {
      console.log("have no rdData");
      return {
        statusCode: 404,
        status: 'error',
        data: { message: "Data for Annotations are not found"}
      }
    }
  }
this.done();
})

I want to return the response of the Promise as my response of endpoint , but it doesn't seems to work correctly, any suggestion @kahmali ?

@SaydChada
Copy link

Have you tried using fibers/Future to handle async response?

@achirkof
Copy link

Hi @gurjit03 !
I'm faced with same problem. Have you found a solution? Could you please share it? Thanks!

@gurjit03
Copy link
Author

gurjit03 commented Aug 4, 2018

@achirkof It's hard to recall. Since it's quite long ago. I am not in touch with the meteor restivus since then. But as far as I remember, I tried some other approach to accomplish the task.

@achirkof
Copy link

achirkof commented Aug 4, 2018

@gurjit03 I have solved it finally. Thank you for feedback.

@gurjit03
Copy link
Author

gurjit03 commented Aug 4, 2018

@achirkof then kindly share it might be helpful for people coming to this thread.

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

3 participants