/*

    #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
      This file is part of the Smart Developer Hub Project:
        http://www.smartdeveloperhub.org/
      Center for Open Middleware
            http://www.centeropenmiddleware.com/
    #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
      Copyright (C) 2015 Center for Open Middleware.
    #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
      Licensed under the Apache License, Version 2.0 (the "License");
      you may not use this file except in compliance with the License.
      You may obtain a copy of the License at
                http://www.apache.org/licenses/LICENSE-2.0
      Unless required by applicable law or agreed to in writing, software
      distributed under the License is distributed on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      See the License for the specific language governing permissions and
     limitations under the License.
    #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
*/

'use strict';

var url = require('url');

var Metric = require('./MetricService');

module.exports.metricList = function metricList (req, res) {

    var callback = function(result) {
        res.setHeader('Access-Control-Allow-Origin', '*');

        if(typeof result !== 'undefined') {
            res.setHeader('Content-Type', 'application/json');
            res.end(JSON.stringify(result || {}, null, 2));
        } else {
            res.end();
        }
    };

    Metric.metricList(callback);
};

module.exports.getMetric = function getMetric (req, res) {
    var mid = req.swagger.params['mid'].value;
    var rid = req.swagger.params['rid'].value;
    var uid = req.swagger.params['uid'].value;
    var from = req.swagger.params['from'].value;
    var to = req.swagger.params['to'].value;
    var accumulated = req.swagger.params['accumulated'].value;
    var max = req.swagger.params['max'].value;
    var aggr = req.swagger.params['aggr'].value;

    var callback = function(result) {
        res.setHeader('Access-Control-Allow-Origin', '*');

        if(typeof result !== 'undefined') {
            res.setHeader('Content-Type', 'application/json');
            res.end(JSON.stringify(result || {}, null, 2));
        } else {
            res.statusCode = 404; // HTTP status 404: NotFound
            res.end();
        }
    };

    Metric.getMetric(mid, rid, uid, from, to, accumulated, max, aggr, callback);
};

@@ -2237,32 +2237,230 @@
  'undefined') %7B%0A
+            if(typeof result == 'number') %7B%0A                // specific error%0A                res.statusCode = result;%0A                res.end();%0A            %7D else %7B%0A                // success%0A    
             res.
@@ -2498,32 +2498,36 @@
 ication/json');%0A
+    
             res.
@@ -2562,32 +2562,46 @@
  %7B%7D, null, 2));%0A
+            %7D%0A
         %7D else %7B
@@ -2634,41 +2634,12 @@
 e = 
-404; // HTTP status 404: NotFound
+500;
 %0A   

Improve getMetric error control