Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion course-04/exercises/c4-client-master/package.json
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"axios": "^0.18.1",
"axios": "^0.30.2",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

This upgrade to axios v0.30.2 introduces a breaking change that will likely cause your API calls to fail.

Starting with axios v0.19.0, JavaScript objects are automatically serialized to JSON for requests with Content-Type: 'application/json'. Your current code in src/api/todos-api.ts manually stringifies the data for POST and PATCH requests, for example:

// src/api/todos-api.ts:24
const response = await Axios.post(`${apiEndpoint}/todos`,  JSON.stringify(newTodo), { /* ... */ });

With the new axios version, this will lead to double-encoded JSON, breaking your backend integration.

To fix this, you must remove the JSON.stringify() calls in createTodo and patchTodo functions and pass the objects directly.

Example for createTodo:

// src/api/todos-api.ts
export async function createTodo(
  idToken: string,
  newTodo: CreateTodoRequest
): Promise<Todo> {
  const response = await Axios.post(`${apiEndpoint}/todos`, newTodo, { // No JSON.stringify
    headers: {
      'Content-Type': 'application/json',
      'Authorization': `Bearer ${idToken}`
    }
  })
  return response.data.item
}

The same change is needed for patchTodo. This is a critical fix required for the app to function after this dependency upgrade.

"dateformat": "^3.0.3",
"immutability-helper": "^3.0.1",
"react": "^16.8.6",
Expand Down