Merge pull request #1291 from MarcelRobitaille/axios-logging

Add debug logging on every network request
This commit is contained in:
Christian Wolf 2022-10-27 13:44:30 +02:00 коммит произвёл GitHub
Родитель 02c164a55c 5f6f59da67
Коммит 78312b9c34
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 37 добавлений и 17 удалений

Просмотреть файл

@ -52,6 +52,8 @@
[#1285](https://github.com/nextcloud/cookbook/pull/1285) @christianlupus [#1285](https://github.com/nextcloud/cookbook/pull/1285) @christianlupus
- Add logging to diagnose bugs in production - Add logging to diagnose bugs in production
[#1283](https://github.com/nextcloud/cookbook/pull/1283) @MarcelRobitaille [#1283](https://github.com/nextcloud/cookbook/pull/1283) @MarcelRobitaille
- Log every network request
[#1291](https://github.com/nextcloud/cookbook/pull/1291) @MarcelRobitaille
### Documentation ### Documentation
- Fix bad writing - Fix bad writing

Просмотреть файл

@ -1,79 +1,97 @@
import Vue from "vue"
import axios from "@nextcloud/axios" import axios from "@nextcloud/axios"
import { generateUrl } from "@nextcloud/router" import { generateUrl } from "@nextcloud/router"
const instance = axios.create()
const baseUrl = `${generateUrl("apps/cookbook")}/webapp` const baseUrl = `${generateUrl("apps/cookbook")}/webapp`
// Add a debug log for every request
instance.interceptors.request.use((config) => {
Vue.$log.debug(
`Making "${config.method}" request to "${config.url}"`,
config
)
const contentType = config.headers[config.method]["Content-Type"]
if (!["application/json", "text/json"].includes(contentType)) {
Vue.$log.warn(
`Request to "${config.url}" is using Content-Type "${contentType}", not JSON`
)
}
return config
})
axios.defaults.headers.common.Accept = "application/json" axios.defaults.headers.common.Accept = "application/json"
function createNewRecipe(recipe) { function createNewRecipe(recipe) {
return axios.post(`${baseUrl}/recipes`, recipe) return instance.post(`${baseUrl}/recipes`, recipe)
} }
function getRecipe(id) { function getRecipe(id) {
return axios.get(`${baseUrl}/recipes/${id}`) return instance.get(`${baseUrl}/recipes/${id}`)
} }
function getAllRecipes() { function getAllRecipes() {
return axios.get(`${baseUrl}/recipes`) return instance.get(`${baseUrl}/recipes`)
} }
function getAllRecipesOfCategory(categoryName) { function getAllRecipesOfCategory(categoryName) {
return axios.get(`${baseUrl}/category/${categoryName}`) return instance.get(`${baseUrl}/category/${categoryName}`)
} }
function getAllRecipesWithTag(tags) { function getAllRecipesWithTag(tags) {
return axios.get(`${baseUrl}/tags/${tags}`) return instance.get(`${baseUrl}/tags/${tags}`)
} }
function searchRecipes(search) { function searchRecipes(search) {
return axios.get(`${baseUrl}/search/${search}`) return instance.get(`${baseUrl}/search/${search}`)
} }
function updateRecipe(id, recipe) { function updateRecipe(id, recipe) {
return axios.put(`${baseUrl}/recipes/${id}`, recipe) return instance.put(`${baseUrl}/recipes/${id}`, recipe)
} }
function deleteRecipe(id) { function deleteRecipe(id) {
return axios.delete(`${baseUrl}/recipes/${id}`) return instance.delete(`${baseUrl}/recipes/${id}`)
} }
function importRecipe(url) { function importRecipe(url) {
return axios.post(`${baseUrl}/import`, `url=${url}`) return instance.post(`${baseUrl}/import`, `url=${url}`)
} }
function getAllCategories() { function getAllCategories() {
return axios.get(`${baseUrl}/categories`) return instance.get(`${baseUrl}/categories`)
} }
function updateCategoryName(oldName, newName) { function updateCategoryName(oldName, newName) {
return axios.put(`${baseUrl}/category/${encodeURIComponent(oldName)}`, { return instance.put(`${baseUrl}/category/${encodeURIComponent(oldName)}`, {
name: newName, name: newName,
}) })
} }
function getAllKeywords() { function getAllKeywords() {
return axios.get(`${baseUrl}/keywords`) return instance.get(`${baseUrl}/keywords`)
} }
function getConfig() { function getConfig() {
return axios.get(`${baseUrl}/config`) return instance.get(`${baseUrl}/config`)
} }
function updatePrintImageSetting(enabled) { function updatePrintImageSetting(enabled) {
return axios.post(`${baseUrl}/config`, { print_image: enabled ? 1 : 0 }) return instance.post(`${baseUrl}/config`, { print_image: enabled ? 1 : 0 })
} }
function updateUpdateInterval(newInterval) { function updateUpdateInterval(newInterval) {
return axios.post(`${baseUrl}/config`, { update_interval: newInterval }) return instance.post(`${baseUrl}/config`, { update_interval: newInterval })
} }
function updateRecipeDirectory(newDir) { function updateRecipeDirectory(newDir) {
return axios.post(`${baseUrl}/config`, { folder: newDir }) return instance.post(`${baseUrl}/config`, { folder: newDir })
} }
function reindex() { function reindex() {
return axios.post(`${baseUrl}/reindex`) return instance.post(`${baseUrl}/reindex`)
} }
export default { export default {