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