Skip to content

Commit

Permalink
Merge pull request #1405 from MarcelRobitaille/1185-add-network-logging
Browse files Browse the repository at this point in the history
Add network logging for responses, not only requests
  • Loading branch information
christianlupus authored Mar 17, 2023
2 parents 6600760 + 0d0fad8 commit c855a5d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,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
Original file line number Diff line number Diff line change
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 c855a5d

Please sign in to comment.