Browse --- Chat --- Wekan

Commit 61f6d685 authored by kc's avatar kc
Browse files

Check responses before parsing. Use dev image tag in dev inv

parent d985d8a0
Showing with 27 additions and 9 deletions
+27 -9
......@@ -15,6 +15,12 @@ function defaultMessage(type, err) {
window.HOST = location.protocol+"//"+location.host;
// TODO: Check the return status of our call. If we get a 404 try again X times
// until we either get a response or hit the retry limit.
// On a reverse proxy server we should actually try capturing any 404's (if they make it there)
// and retrying on another docker task (if it works that way)
const api = {
get: function (type, opts, callback) {
......
......@@ -47,6 +47,17 @@ module.exports = {
if(this.AUTH_URL) { return this.AUTH_URL }
},
checkResponse(raw, requestFrom) {
let res = ""
try { res = raw ? JSON.parse(raw) : "" }
catch(e) {
console.log(`ERR - ${requestFrom} Invalid request/url`);
console.log(`ERR - ${requestFrom}:`, e);
return false
}
return true
},
checkAccess({headers = {}, app, accessReq }) {
let customHeaders = {
......@@ -67,12 +78,9 @@ module.exports = {
res.on("data", (data) => raw += data.toString())
res.on("err", (err) => { reject(err) })
res.on("end", () => {
let res = ""
try { res = raw ? JSON.parse(raw) : "" }
catch(e) {
console.log("Invalid request/url - options:", options);
console.log("e:", e);
}
let responseIsOk = this.checkResponse(raw, "NPMAUTH.CHECKACCESS")
if(!responseIsOk) { return respond({status: false}) }
let res = JSON.parse(raw)
let status = res.status ? res.status : false
let hasPermissions = status && res.access[app] >= res.access["levels"][accessReq]
resolve({status: status, hasPermissions})
......@@ -107,7 +115,9 @@ module.exports = {
respond({status: false, data: "Server error"})
})
res.on("end", () => {
let res = raw ? JSON.parse(raw) : ""
let responseIsOk = this.checkResponse(raw, "NPMAUTH.GETMENU")
if(!responseIsOk) { return respond({status: false}) }
let res = JSON.parse(raw)
if(!res.status) {
if(res.data) {
console.log(res.data);
......@@ -148,6 +158,8 @@ module.exports = {
res.on("data", (data) => raw += data.toString())
res.on("err", (err) => { reject(err) })
res.on("end", () => {
let responseIsOk = this.checkResponse(raw, "NPMAUTH.LOGOUT")
if(!responseIsOk) { return respond({status: false}) }
let res = JSON.parse(raw)
resolve({status: res.status})
})
......
{
"name": "os-npm-util",
"version": "0.4.0",
"version": "0.4.1",
"description": "NPM Modules",
"main": "index.js",
"dependencies": {
......
......@@ -9,7 +9,7 @@ const yaml = require("js-yaml");
const yamlFile = fs.readFileSync("/home/app/docker-compose.yml")
const yamlObj = yaml.safeLoad(yamlFile)
const MAIN_SERVICE = yamlObj.services.main
const MAIN_SERVICE = process.env.DEV_ENV ? yamlObj.services.dev : yamlObj.services.main
const DOCKER_IMAGE = MAIN_SERVICE.image
const IMAGE_VER = DOCKER_IMAGE.match(/:(.+)/)[1]
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment