Commit a3147fc7 authored by jackie / Andrea Ida Malkah Klaura's avatar jackie / Andrea Ida Malkah Klaura
Browse files

FIX #11: check for 409 Conflict when deleting files

parent 114c0c31
......@@ -1005,20 +1005,37 @@ export default {
}
},
// Deletes a file with a specific, calling the AuRa tank API and afterwards
// Deletes a file with a specific ID calling the AuRa tank API and afterwards
// fetching a fresh list of files from it.
deleteFile: function (id) {
var uri = process.env.VUE_APP_API_TANK + 'shows/' + this.shows[this.currentShow].slug + '/files/' + id
let uri = process.env.VUE_APP_API_TANK + 'shows/' + this.shows[this.currentShow].slug + '/files/' + id
// TODO: add mechanism to indicate the running delete request in the files table
axios.delete(uri, {
withCredentials: true,
headers: { 'Authorization': 'Bearer ' + this.$parent.user.access_token },
}).then(
}).then(() => {
this.$log.debug(`Fetching files for show ${this.shows[this.currentShow].slug} (ID: ${id})`)
this.fetchFiles(this.shows[this.currentShow].slug)
).catch(error => {
}).catch(error => {
// if there was a 409 Conflict response it means, that this file is
// still used in one or more playlists.
if (error.response.status === 409) {
let pls = error.response.data.details.playlists.length
let msg = 'Cannot delete file. Still used in ' + pls + ' playlists:\n\n'
for (let pl of error.response.data.details.playlists) {
msg += 'ID: ' + pl.id
if (pl.description) {
msg += ' (' + pl.description + ')'
}
msg += '\n'
}
msg += '\nIf you want to delete the file, remove it from those playlists first.'
alert(msg)
} else {
this.$log.error(error.response.status + ' ' + error.response.statusText)
this.$log.error(error.response)
alert('Error: could not delete file. See console for details.')
}
})
},
......
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