@@ -4,6 +4,7 @@ import ReportService from './report/report-service';
44import fs from 'node:fs' ;
55import path from 'node:path' ;
66import Log from './context/log' ;
7+ import { Response } from './services/response' ;
78
89showCoverage = function ( params , req , res , next ) {
910 let options = {
@@ -24,20 +25,20 @@ getAsset = function (params, req, res, next) {
2425 fs . readFile ( assetsDir + '/vendor/' + filename , function ( err , fileContent ) {
2526 /* istanbul ignore else */
2627 if ( err ) {
27- console . error ( err ) ;
28+ Log . error ( err ) ;
2829 return next ( ) ;
2930 }
30- res . json ( fileContent ) ;
31+ Response . send ( { res , message : fileContent } ) ;
3132 } ) ;
3233 } ) ;
3334 } else {
3435 fs . readFile ( assetsDir + '/' + filename , function ( err , fileContent ) {
3536 /* istanbul ignore else */
3637 if ( err ) {
37- console . error ( err ) ;
38+ Log . error ( err ) ;
3839 return next ( ) ;
3940 }
40- res . json ( fileContent ) ;
41+ Response . send ( { res , message : fileContent } ) ;
4142 } ) ;
4243 }
4344 } ) ;
@@ -47,8 +48,11 @@ addClientCoverage = function (params, req, res, next) {
4748 var body = req . body ;
4849 /* istanbul ignore else */
4950 if ( ! body ) {
50- res . status ( 400 ) ;
51- return res . end ( ) ;
51+ return Response . send ( {
52+ res,
53+ status : 400 ,
54+ end : true
55+ } ) ;
5256 }
5357
5458 var clientCoverage ;
@@ -60,10 +64,16 @@ addClientCoverage = function (params, req, res, next) {
6064 }
6165 if ( clientCoverage ) {
6266 Core . mergeCoverageWith ( clientCoverage ) ;
63- res . json ( { type : 'success' } ) ;
67+ Response . send ( {
68+ res,
69+ json : { type : 'success' }
70+ } ) ;
6471 } else {
65- res . status ( 400 ) ;
66- res . send ( 'Nothing has been imported' ) ;
72+ Response . send ( {
73+ res,
74+ status : 400 ,
75+ message : 'Nothing has been imported'
76+ } ) ;
6777 }
6878} ;
6979
@@ -76,17 +86,23 @@ exportFile = function (params, req, res, next) {
7686 reportService . generateReport ( res , type , { } ) ;
7787 } catch ( e ) {
7888 Log . error ( 'Failed to export' , e , e . stack ) ;
79- res . status ( 400 ) ;
80- res . send ( 'Nothing has been export' ) ;
89+ Response . send ( {
90+ res,
91+ status : 400 ,
92+ message : 'Nothing has been export'
93+ } ) ;
8194 }
8295} ;
8396importCoverage = function ( params , req , res , next ) {
8497 try {
8598 Core . importCoverage ( res ) ;
8699 } catch ( e ) {
87100 Log . error ( 'Failed to import' , e , e . stack ) ;
88- res . status ( 400 ) ;
89- res . send ( 'No file has been import' ) ;
101+ Response . send ( {
102+ res,
103+ status : 400 ,
104+ message : 'No file has been import'
105+ } ) ;
90106 }
91107} ;
92108
0 commit comments