Skip to content
This repository has been archived by the owner on Sep 18, 2019. It is now read-only.

Debug: internal, implementation, error Error: handler method did not return a value, a promise, or throw an error #643

Closed
shushantkumar opened this issue Mar 11, 2018 · 3 comments
Labels

Comments

@shushantkumar
Copy link

Hi,
I'm using hapi version ^17.2.1 and I have a problem because I get an error in route handler:
Debug: internal, implementation, error
Error: handler method did not return a value, a promise, or throw an error

I am using MySQL database. So when I'm sending a query to the database and getting the result from the database. Using console.log, it is getting printed in the console but since I'm returning the result there itself within the query as a response it is not returning anything from the main handler function(case-1). Storing the result from the database in a new variable outside scope of query function and returning it as a response outside query function doesn't help either (case-2), it just returns a blank response.

case-1
`server.route(

{

method:'GET',

path:'/productget',

config:{
    handler: (request, h) =>{           
        var sql = "select * from product_details";
        con.query(sql,function (err, result) {
            if (err) throw err;    
           console.log(result);
           return h.response(result); 
        }); 
    },
    validate: {
        failAction: Relish.failAction,
    }   
}

});`

case-2
`server.route(

{

method:'GET',

path:'/productget',
config:{
    let temp;
    handler: (request, h) =>{           
        var sql = "select * from product_details";
        con.query(sql,this,function (err, result) {
            if (err) throw err;    
           console.log(result);
           this.temp=result;
        }); 
      return h.response(temp); 
    },
    validate: {
        failAction: Relish.failAction,
    }   
}

});`

Can someone help me out in this how can I return a response from server within the query function or using any other method?

@Marsup
Copy link

Marsup commented Mar 11, 2018

Asked and answered on the slack channel.

@Marsup Marsup closed this as completed Mar 11, 2018
@toddalbert
Copy link

What was the answer? These two posts just take us in a loop.

@shushantkumar
Copy link
Author

shushantkumar commented Jun 22, 2018

Hi
Basically, it needs to be done as follows

server.route(
    {
    method:'GET',
    path:'/productget',
    config:{
        handler: (request, h) =>{

            let notes= db.query("select * from product_details")
            //console.log(notes);
            return notes;
        },
        description: 'Get product data',
        notes: 'product Get request',
        tags: ['api'],
        validate: {
            failAction: Relish.failAction,
        }   
    }
});

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

No branches or pull requests

3 participants