Commit 12c300f1 authored by priit's avatar priit
Browse files

Utiliidi vea korral tagasta veateade

parent 4ebd0108
var logger = require('log4js').getLogger('router_middleware');
var express = require('express');
module.exports = {
common: function(err, req, res, next) {
......
var logger = require('log4js').getLogger('router_middleware');
var logger = require('log4js').getLogger('command_model');
var sessionService = require('../service/sessionService');
function CommandModel(){
......
......@@ -12,12 +12,19 @@ var Session = function( id ){
this.requestFiles = {};
this.data = null;
this.outputFiles = {};
this.errors = null;
};
Session.prototype.addOutputFile = function(key, path){
this.outputFiles[key] = path;
};
Session.prototype.setErrors = function(errors, path){
this.errors = errors;
this.isSuccess = false;
this.message = Session.messages.ERROR
};
Session.messages = {
RUNNING: 'RUNNING',
OK: 'OK',
......
......@@ -12,9 +12,9 @@ function LocalExecutor() {
this.execute = function (commandModel, callback) {
var response = {
message: null,
isSuccess:true,
stdOutPath: sessionService.getNewSessionFilePath(commandModel.session)
stdOutPath: sessionService.getNewSessionFilePath(commandModel.session),
errors: []
};
var localCommand = new LocalCommand(commandModel).generate();
......@@ -44,6 +44,13 @@ function LocalExecutor() {
process.stderr.on('data', function (data) {
logger.error('Got error: ' + data);
response.isSuccess = false;
response.errors.push({util:data});
});
process.on('error', function (data) {
logger.error('Got error: ' + data);
response.isSuccess = false;
response.errors.push({util:data});
});
process.on('close', function (code, signal) {
......
......@@ -165,6 +165,10 @@ function SessionService() {
response.success = session.success;
response.message = session.message;
if(session.errors != null){
response.errors = session.errors;
}
if (session.message == Session.messages.RUNNING) {
response.recheckInterval = session.recheckInterval;
}
......
......@@ -7,8 +7,6 @@ var SessionService = require('./../src/service/sessionService');
var CommandModel = require('../src/mapper/commandModel');
var fs = require('fs');
function ContentTokenizer(){
var self = this;
......@@ -22,9 +20,15 @@ function ContentTokenizer(){
if(err) return callback(err);
localExecutor.execute( model, function ( err, response ) {
if(err) return callback(err);
logger.debug('Väline programm on lõpetanud');
if(err){
session.setErrors(err);
return callback( err, session );
}
if(!response.isSuccess){
session.setErrors(response.errors);
return callback( err, session );
}
fs.readFile(model.outputPaths.outputPath1, function (err, output) {
if(err) return callback(err);
......
......@@ -2,7 +2,6 @@ var logger = require('log4js').getLogger('wrapper');
var config = require('./../config');
var localExecutor = require('./../src/service/executor/localExecutor');
var Session = require('../src/model/session');
var SessionService = require('./../src/service/sessionService');
var CommandModel = require('../src/mapper/commandModel');
var fs = require('fs');
......@@ -23,8 +22,7 @@ function ContentTokenizer(){
if(response.isSuccess){
session.message = Session.messages.OK;
} else {
session.message = Session.messages.ERROR;
session.success = false;
session.setErrors(response.errors);
}
session.addOutputFile('output', response.stdOutPath);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment