Thuta Learning
ExercisesWeb Developmentintermediate

Practice Set 2: Combining CRUD, Pagination & Error Handling

Relax. We'll talk through this in plain words — no textbook voice.

What you'll walk away with

  • Work through Practice Set 2: Combining CRUD, Pagination & Error Handling on your own
  • Practice the skills you've already learned until they're solid
  • Get comfortable finding bugs, fixing them, and checking your own work

Take a moment to think about this

This Practice Set steps things up a level from Practice Set 1 — the goal is to combine Create/Read/Update/Delete, pagination query params, and error/rate-limit handling all at once. In a real project, you can never be sure every single request will succeed, so these four tasks are designed to get you thinking not just about the success flow but the error flow too. After finishing each task, compare your code against the Common Mistakes listed below.

Exercises

Task 1: create 3 users with a loop using POST, then call GET /v1/users?page=1&limit=2 and page=2&limit=2, and check that all 3 users come back split correctly across the two pages. Task 2: update one of the created users' email with a PUT request, then call GET again to verify the change actually took. Task 3: delete a user, then call GET again with that same id and confirm you get a 404 status back. Task 4: deliberately set the token to something wrong, send the request, catch the 401 error, and write an error handler that outputs a user-friendly message like "Token မှားနေပါတယ်၊ ပြန်စစ်ဆေးပါ" ("That token looks wrong — please double-check it").

Code Example

javascript
// Task 1 skeleton
async function createThreeUsers() {
  const users = [
    { name: 'A', email: 'a@example.com' },
    { name: 'B', email: 'b@example.com' },
    { name: 'C', email: 'c@example.com' },
  ];
  for (const u of users) {
    await createUser(u.name, u.email); // Part 2 ရဲ့ function ကို ပြန်သုံးနိုင်ပါတယ်
  }
}

// Task 4 skeleton
async function testInvalidToken() {
  try {
    const res = await fetch('https://api.example.com/v1/users', {
      headers: { Authorization: 'Bearer WRONG_TOKEN' },
    });
    if (res.status === 401) {
      throw new Error('UNAUTHORIZED');
    }
  } catch (err) {
    console.error('Token မှားနေပါတယ်၊ ပြန်စစ်ဆေးပါ');
  }
}
You should see
For Tasks 1-3, you should be able to confirm from the console output that the pagination, update, and delete flows each worked correctly, and Task 4 should print out a single friendly error message.

5-Minute Try-It

Within 5 minutes, run Task 1 and manually count how many users show up in the page=1, limit=2 result.

A Quick Word of Caution

Firing off a bunch of create requests in a loop all in parallel over one connection can hit the rate limit fast, so make sure Task 1 runs sequentially (one await finishing before the next one starts).

Easy traps

  • Putting pagination's page/limit into the query string as a raw string without URL-encoding it, which breaks when a value contains a space
  • Skipping the follow-up GET after a delete and just assuming it's 'done', without actually confirming the data is gone

Now Try It Yourself

Within 5 minutes, run Task 1 and manually count how many users show up in the page=1, limit=2 result.

You'll know it worked when: For Tasks 1-3, you should be able to confirm from the console output that the pagination, update, and delete flows each worked correctly, and Task 4 should print out a single friendly error message.

Practice Set 2: Combining CRUD, Pagination & Error Handling | Thuta Learning