relaxed some http reply checks

This commit is contained in:
dcore94 2023-05-18 10:09:47 +02:00
parent a5d8dc603e
commit 9fac4a968e
1 changed files with 15 additions and 15 deletions

View File

@ -222,8 +222,8 @@ class CCPExecutionHistory extends HTMLElement {
refreshExecution(id){ refreshExecution(id){
this.#boot.secureFetch(`${this.#serviceurl}/executions?id=${id}`).then(reply =>{ this.#boot.secureFetch(`${this.#serviceurl}/executions?id=${id}`).then(reply =>{
if(reply.status === 200) return reply.json(); if(reply.ok) return reply.json();
else throw `Unable to load execution ${id}` else throw `Unable to load execution ${id}. Check console.`
}).then(data=>{ }).then(data=>{
//this may occur for timing issues since workflow start is async //this may occur for timing issues since workflow start is async
const exec = data.length === 0 ? { id : id} : data[0] const exec = data.length === 0 ? { id : id} : data[0]
@ -242,15 +242,15 @@ class CCPExecutionHistory extends HTMLElement {
deleteExecution(id){ deleteExecution(id){
this.#boot.secureFetch(`${this.#serviceurl}/executions/${id}`, { method: "DELETE"}).then(reply =>{ this.#boot.secureFetch(`${this.#serviceurl}/executions/${id}`, { method: "DELETE"}).then(reply =>{
if(reply.status === 200) this.refreshExecutions(); if(reply.ok) this.refreshExecutions();
else throw `Unable to delete execution ${id}` else throw `Unable to delete execution ${id}. Check console.`
}).catch(err=>{ console.error(err)}) }).catch(err=>{ console.error(err)})
} }
refreshExecutions(){ refreshExecutions(){
this.#boot.secureFetch(`${this.#serviceurl}/executions`).then(reply =>{ this.#boot.secureFetch(`${this.#serviceurl}/executions`).then(reply =>{
if(reply.status === 200) return reply.json(); if(reply.ok) return reply.json();
else throw "Unable to load executions" else throw "Unable to load executions. Check console."
}).then(data=>{ }).then(data=>{
this.#data = data this.#data = data
this.updateList() this.updateList()
@ -285,8 +285,8 @@ class CCPExecutionHistory extends HTMLElement {
download(url, name) { download(url, name) {
this.#boot.secureFetch(url).then(reply => { this.#boot.secureFetch(url).then(reply => {
if (reply.status !== 200) { if (!reply.ok) {
throw "Unable to download" throw "Unable to download. Check console."
} }
return reply.blob() return reply.blob()
@ -305,7 +305,7 @@ class CCPExecutionHistory extends HTMLElement {
export(id, mime, filename){ export(id, mime, filename){
this.#boot.secureFetch(`${this.#serviceurl}/executions/${id}`, this.#boot.secureFetch(`${this.#serviceurl}/executions/${id}`,
{ method: "GET", headers : { "Accept" : mime} }).then(reply =>{ { method: "GET", headers : { "Accept" : mime} }).then(reply =>{
if (reply.status !== 200) { if (!reply.ok) {
throw "Unable to export " + mime throw "Unable to export " + mime
} }
return reply.blob() return reply.blob()
@ -323,8 +323,8 @@ class CCPExecutionHistory extends HTMLElement {
reexecute(id,level){ reexecute(id,level){
this.#boot.secureFetch(`${this.#serviceurl}/executions/${id}/level/${level}`, { method: "POST" }) this.#boot.secureFetch(`${this.#serviceurl}/executions/${id}/level/${level}`, { method: "POST" })
.then(reply =>{ .then(reply =>{
if (reply.status !== 200) { if (!reply.ok) {
throw "Unable to re-execute" throw "Unable to re-execute. Check console."
} }
return reply.json() return reply.json()
}).then(data=>{ }).then(data=>{
@ -342,7 +342,7 @@ class CCPExecutionHistory extends HTMLElement {
}, formdata) }, formdata)
this.#boot.secureFetch(`${this.#serviceurl}/executions`, { body: formdata, method : "POST"}) this.#boot.secureFetch(`${this.#serviceurl}/executions`, { body: formdata, method : "POST"})
.then(reply=>{ .then(reply=>{
if (reply.status !== 200) { if (!reply.ok) {
throw "Unable to import" throw "Unable to import"
}else return reply.text() }else return reply.text()
}).then(data=>{ }).then(data=>{
@ -354,7 +354,7 @@ class CCPExecutionHistory extends HTMLElement {
generateCode(id, mime, filename){ generateCode(id, mime, filename){
this.#boot.secureFetch(`${this.#serviceurl}/executions/${id}/code`, this.#boot.secureFetch(`${this.#serviceurl}/executions/${id}/code`,
{ method: "GET", headers : { "Accept" : mime} }).then(reply =>{ { method: "GET", headers : { "Accept" : mime} }).then(reply =>{
if (reply.status !== 200) { if (!reply.ok) {
throw "Unable to generate code for " + mime throw "Unable to generate code for " + mime
} }
return reply.blob() return reply.blob()
@ -372,7 +372,7 @@ class CCPExecutionHistory extends HTMLElement {
toArchive(id){ toArchive(id){
this.#boot.secureFetch(`${this.#serviceurl}/executions/${id}/archive`, { method: "POST" }) this.#boot.secureFetch(`${this.#serviceurl}/executions/${id}/archive`, { method: "POST" })
.then(reply =>{ .then(reply =>{
if (reply.status !== 200) { if (!reply.ok) {
throw "Unable to archive" throw "Unable to archive"
} }
}).catch(err=>{ alert(err)}) }).catch(err=>{ alert(err)})
@ -382,7 +382,7 @@ class CCPExecutionHistory extends HTMLElement {
if(url){ if(url){
this.#boot.secureFetch(`${this.#serviceurl}/executions/archive?url=${url}`) this.#boot.secureFetch(`${this.#serviceurl}/executions/archive?url=${url}`)
.then(reply =>{ .then(reply =>{
if (reply.status !== 200) { if (!reply.ok) {
throw "Unable to fetch from archive" throw "Unable to fetch from archive"
} }
return reply.text() return reply.text()