Skip to content

Commit

Permalink
Add network logging for responses, not only requests
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Robitaille <mail@marcelrobitaille.me>
Signed-off-by: Christian Wolf <github@christianwolf.email>
  • Loading branch information
MarcelRobitaille authored and Christian Wolf committed Mar 16, 2023
1 parent 964aee2 commit 0d0fad8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,8 @@
[#1442](https://github.com/nextcloud/cookbook/pull/1442) @christianlupus
- Reorder arrows are no longer hidden
[#1446](https://github.com/nextcloud/cookbook/pull/1446) @christianlupus
- Add network logging for responses, not only requests
[1405](https://github.com/nextcloud/cookbook/pull/1405) @MarcelRobitaille

### Maintenance
- Update dependency for GitHub pages builder
Expand Down
15 changes: 13 additions & 2 deletions src/js/api-interface.js
Expand Up @@ -10,18 +10,29 @@ 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}"`,
`[axios] 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`
`[axios] Request to "${config.url}" is using Content-Type "${contentType}", not JSON`
)
}
return config
})

instance.interceptors.response.use(
(response) => {
Vue.$log.debug("[axios] Received response", response)
return response
},
(error) => {
Vue.$log.warn("[axios] Received error", error)
return Promise.reject(error)
}
)

axios.defaults.headers.common.Accept = "application/json"

function createNewRecipe(recipe) {
Expand Down

0 comments on commit 0d0fad8

Please sign in to comment.