Frank Jogeleit 2c712a0557 add persist handler
Signed-off-by: Frank Jogeleit <frank.jogeleit@lovoo.com>
2023-02-04 13:28:08 +01:00

30 lines
743 B
JavaScript

'use strict'
const axios = require('axios');
const fs = require('fs');
const { GithubActions } = require('../githubActions');
/**
* @param {string} filePath
* @param {GithubActions} actions
*
* @returns {(response: axios.AxiosResponse) => void}
*/
const createPersistHandler = (filePath, actions) => (response) => {
let data = response.data
if (typeof data == 'object') {
data = JSON.stringify(data)
}
fs.writeFile(filePath, data, err => {
if (!err) {
actions.info(`response persisted successfully at ${filePath}`)
return
}
actions.warning(JSON.stringify({ message: error.message, data: response.data }))
})
}
module.exports = { createPersistHandler }