김서영

api try catch/ add header to api request

......@@ -37,13 +37,22 @@ apiRequest.ETRI = async ( query, argument ) => {
return new Promise( ( resolve, reject ) => {
let apiReqJson = apiRequestJsonFrame;
apiReqJson.argument = argument;
let apiReqOption = { uri : URL.ETRI + query, body : JSON.stringify( apiReqJson ) };
rp.post( apiReqOption )
.then( ( body ) => {
body = JSON.parse( body );
resolve( body );
})
let apiReqOption = { headers: {
"Accept": "application/json",
"Content-Type": "application/json",
},uri : URL.ETRI + query, body : JSON.stringify( apiReqJson ) };
rp.post( apiReqOption )
.then( ( body ) => {
body = JSON.parse( body );
if( body.result == "-1" ) {
throw new Error( body.reason );
}
resolve( body );
})
.catch( ( err ) => {
throw new Error( err );
});
})
}
......