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

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

Closed
shushantkumar opened this issue Mar 11, 2018 · 1 comment
Assignees

Comments

@shushantkumar
Copy link

shushantkumar commented Mar 11, 2018

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 Marsup self-assigned this Mar 11, 2018
@Marsup
Copy link
Contributor

Marsup commented Mar 11, 2018

Duplicate of outmoded/discuss#643.

@Marsup Marsup closed this as completed Mar 11, 2018
@outmoded outmoded locked as off-topic and limited conversation to collaborators Mar 11, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants