que obtener ejemplos div contenido con agregar javascript promise bluebird

javascript - obtener - Se creó una promesa en un controlador pero no se devolvió



innerhtml que es (1)

Recibirá la advertencia porque, como dice, no devuelve la promesa del manejador de then .
La mejor forma de rastrear el lugar del rechazo es rastrearlo e ingresarlo. Que no haya ningún rastro de pila sugiere que usted (o una de las bibliotecas que usa) está throw un objeto simple que no es un Error . Intenta encontrar y arreglar eso.

Su llamada debería verse así:

api.getCurrentProcessInstanceTask().then(function(task) { return api.completeTask(task); // ^^^^^^ }).catch(function(err) { // ^^^^^ console.error(err); });

Acabo de empezar a usar las promesas de bluebird y estoy recibiendo un error confuso

Resumen del código

var jQueryPostJSON = function jQueryPostJSON(url, data) { return Promise.resolve( jQuery.ajax({ contentType: "application/json; charset=utf-8", dataType: "json", type: "POST", url: url, data: JSON.stringify(data) }) ).then(function(responseData) { console.log("jQueryPostJSON response " + JSON.stringify(responseData, null, 2)); return responseData; }); }, completeTask = function completeTask(task, variables) { console.log("completeTask called for taskId: "+task.id); //FIXME reform variables according to REST API docs var variables = { "action" : "complete", "variables" : [] }; spin.start(); return jQueryPostJSON(hostUrl + ''service/runtime/tasks/''+task.id, variables) .then(function() { gwl.grrr({ msg: "Completed Task. Definition Key: " + task.taskDefinitionKey, type: "success", displaySec: 3 }); spin.stop(); return null; }); }

La función jQueryPostJSON parece funcionar bien tal como está cuando se usa else en otro lugar, pero en ese caso hay datos devueltos por el servidor.

Cuando se utiliza dentro de una tarea completa, el POST es exitoso, como se puede ver en el lado del servidor, pero nunca se llama a la función en su lugar en la consola obtengo el error

completeTask called for taskId: 102552 bundle.js:20945 spin target: [object HTMLDivElement] bundle.js:20968 spinner started bundle.js:1403 Warning: a promise was created in a handler but was not returned from it at jQueryPostJSON (http://localhost:9000/dist/bundle.js:20648:22) at Object.completeTask (http://localhost:9000/dist/bundle.js:20743:14) at http://localhost:9000/dist/bundle.js:21051:15 From previous event: at HTMLDocument.<anonymous> (http://localhost:9000/dist/bundle.js:21050:10) at HTMLDocument.handleObj.handler (http://localhost:9000/dist/bundle.js:5892:30) at HTMLDocument.jQuery.event.dispatch (http://localhost:9000/dist/bundle.js:10341:9) at HTMLDocument.elemData.handle (http://localhost:9000/dist/bundle.js:10027:28) bundle.js:1403 Unhandled rejection (<{"readyState":4,"responseText":"","sta...>, no stack trace)

La advertencia me da el motivo, ese no es el problema. Es el rechazo no controlado y el hecho de que no hubo ningún error desde el POST.

línea 21050 está aquí Estoy probando la combinación de estos para funciones de módulos separados

jQuery(document).bind(''keydown'', ''ctrl+]'', function() { console.log("test key pressed"); api.getCurrentProcessInstanceTask() .then(function(task) { api.completeTask(task); }); });

La salida de la primera llamada de función api.getCurrentProcessInstanceTask () parece indicar que está funcionando correctamente, pero aquí está de todos modos

getCurrentProcessInstanceTask = function getCurrentProcessInstanceTask() { if (!currentProcess || !currentProcess.id) { return Promise.reject(new Error("no currentProcess is set, cannot get active task")); } var processInstanceId = currentProcess.id; return Promise.resolve(jQuery.get(hostUrl + "service/runtime/tasks", { processInstanceId: processInstanceId })) .then(function(data) { console.log("response: " + JSON.stringify(data, null, 2)); currentProcess.tasks = data.data; // if(data.data.length > 1){ // throw new Error("getCurrentProcessInstanceTask expects single task result. Result listed "+data.data.length+" tasks!"); // } console.log("returning task id: "+data.data[0].id); return data.data[0]; }); },