* v3.14.0 * fix: simplify config fetch interceptor implementation * add `loadRemoteConfig` flag to requests * v3.14.0
26 lines
642 B
JavaScript
26 lines
642 B
JavaScript
import { parseYamlConfig } from "./helpers"
|
|
|
|
export const downloadConfig = (req) => (system) => {
|
|
const {fn: { fetch }} = system
|
|
|
|
return fetch(req)
|
|
}
|
|
|
|
export const getConfigByUrl = (req, cb)=> ({ specActions }) => {
|
|
if (req) {
|
|
return specActions.downloadConfig(req).then(next, next)
|
|
}
|
|
|
|
function next(res) {
|
|
if (res instanceof Error || res.status >= 400) {
|
|
specActions.updateLoadingStatus("failedConfig")
|
|
specActions.updateLoadingStatus("failedConfig")
|
|
specActions.updateUrl("")
|
|
console.error(res.statusText + " " + req.url)
|
|
cb(null)
|
|
} else {
|
|
cb(parseYamlConfig(res.text))
|
|
}
|
|
}
|
|
}
|