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>
  • Loading branch information
MarcelRobitaille committed Dec 29, 2022
1 parent 9284b06 commit ae2e319
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
### Fixed
- Make "None" category string translatable
[1323](https://github.com/nextcloud/cookbook/pull/1344) @seyfeb
- 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
9 changes: 7 additions & 2 deletions src/js/api-interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,23 @@ 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),
(error) => Vue.$log.warn("[axios] Received error", error)
)

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

function createNewRecipe(recipe) {
Expand Down

0 comments on commit ae2e319

Please sign in to comment.