---
id: 641da51a9810e74411262fcc
title: Step 6
challengeType: 0
dashedName: step-6
---

# --description--

The `.catch()` method is another asynchronous JavaScript method you can use to handle errors. This is useful in case the `Promise` gets rejected.

Chain `.catch()` to the last `.then()`. Pass in a callback function with `err` as the parameter. Inside the callback, use `console.error()` to log possible errors to the console with the text `There was an error: ${err}`. Since you're using `err` in the text, don't forget to use a template literal string with backticks (``) instead of single or double quotes.

**Note**: Now you can terminate your code with a semicolon. You couldn't do that in the previous steps because you'll signal to JavaScript to stop parsing your code, which will affect the `fetch()` syntax.

# --hints--

You should use the `fetch()` method to make a `GET` request to `https://cdn.freecodecamp.org/curriculum/news-author-page/authors.json`.

```js
assert.match(code, /fetch\(('|"|`)https:\/\/cdn\.freecodecamp\.org\/curriculum\/news\-author\-page\/authors\.json\1\)/)
```

You should chain another `.then()` to the existing `.then()`.

```js
assert.match(code, /fetch\(('|"|`)https:\/\/cdn\.freecodecamp\.org\/curriculum\/news\-author\-page\/authors\.json\1\)\s*\.then\(\(?res\)?\s*=>\s*res.json\(\)\)\s*\.then\(/)
```

You should add a `data` parameter to your second `.then()` method.

```js
assert.match(code, /fetch\(('|"|`)https:\/\/cdn\.freecodecamp\.org\/curriculum\/news\-author\-page\/authors\.json\1\)\s*\.then\(\(?res\)?\s*=>\s*res.json\(\)\)\s*\.then\(\(?data\)?/)
```

Your second `.then()` method should use arrow function syntax.

```js
assert.match(code, /fetch\(('|"|`)https:\/\/cdn\.freecodecamp\.org\/curriculum\/news\-author\-page\/authors\.json\1\)\s*\.then\(\(?res\)?\s*=>\s*res.json\(\)\)\s*\.then\(\(?data\)?\s*=>\s*/)
```

Your second `.then()` method should have curly braces.

```js
assert.match(code, /fetch\(('|"|`)https:\/\/cdn\.freecodecamp\.org\/curriculum\/news\-author\-page\/authors\.json\1\)\s*\.then\(\(?res\)?\s*=>\s*res.json\(\)\)\s*\.then\(\(?data\)?\s*=>\s*\{\s*\n?\s*/)
```

Your second `.then()` method should log `data` to the console.

```js
assert.match(code, /fetch\(('|"|`)https:\/\/cdn\.freecodecamp\.org\/curriculum\/news\-author\-page\/authors\.json\1\)\s*\.then\(\(?res\)?\s*=>\s*res.json\(\)\)\s*\.then\(\(?data\)?\s*=>\s*\{\s*\n?\s*?console\.log\(data\);?\n?\s*\}\)/)
```

Your second `.then()` should not have a semicolon.

```js
assert.notMatch(code, /fetch\(('|"|`)https:\/\/cdn\.freecodecamp\.org\/curriculum\/news\-author\-page\/authors\.json\1\)\s*\.then\(\(?res\)?\s*=>\s*res.json\(\)\)\s*\.then\(\(?data\)?\s*=>\s*\{\s*\n?\s*?console\.log\(data\);?\n?\s*\}\);/)
```

You should chain the `.catch()` method to the second `.then()` you already have.

```js
assert.match(code, /fetch\(('|"|`)https:\/\/cdn\.freecodecamp\.org\/curriculum\/news\-author\-page\/authors\.json\1\)\s*\.then\(\(?res\)?\s*=>\s*res.json\(\)\)\s*\.then\(\(?data\)?\s*=>\s*\{\s*\n?\s*?console\.log\(data\);?\n?\s*\}\s*\)\n?\s*\.catch\(/)
```

You should add an `err` parameter to your `.catch()` method.

```js
assert.match(code, /fetch\(('|"|`)https:\/\/cdn\.freecodecamp\.org\/curriculum\/news\-author\-page\/authors\.json\1\)\s*\.then\(\(?res\)?\s*=>\s*res.json\(\)\)\s*\.then\(\(?data\)?\s*=>\s*\{\s*\n?\s*?console\.log\(data\);?\n?\s*\}\s*\)\n?\s*\.catch\(\(?err\)?/)
```

Your `.catch()` method should have an arrow function syntax.

```js
assert.match(code, /fetch\(('|"|`)https:\/\/cdn\.freecodecamp\.org\/curriculum\/news\-author\-page\/authors\.json\1\)\s*\.then\(\(?res\)?\s*=>\s*res.json\(\)\)\s*\.then\(\(?data\)?\s*=>\s*\{\s*\n?\s*?console\.log\(data\);?\n?\s*\}\s*\)\n?\s*\.catch\(\(?err\)?\s*=>\s*\{?/)
```

Your `.catch()` method should use `console.error()` to log `err` to the console with the text \``There was an error: ${err}`&#96;. Don't forget to use backticks.

```js
assert.match(code, /fetch\(('|"|`)https:\/\/cdn\.freecodecamp\.org\/curriculum\/news\-author\-page\/authors\.json\1\)\s*\.then\(\(?res\)?\s*=>\s*res.json\(\)\)\s*\.then\(\(?data\)?\s*=>\s*\{\s*\n?\s*?console\.log\(data\);?\n?\s*\}\s*\)\n?\s*\.catch\(\(?err\)?\s*=>\s*\{?\n?(\s*)?console\.error\(`There\swas\san\serror:\s?\$\{err\}`\);?\n?(\s*)?\}?\)\s*;?/)
```

# --seed--

## --seed-contents--

```html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>freeCodeCamp News Author Page</title>
    <link rel="stylesheet" href="./styles.css" />
  </head>
  <body>
    <h1 class="title">freeCodeCamp News Author Page</h1>

    <main>
      <div id="author-container"></div>
      <button class="btn" id="load-more-btn">Load More Authors</button>
    </main>

    <script src="./script.js"></script>
  </body>
</html>
```

```css
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --main-bg-color: #1b1b32;
  --light-grey: #f5f6f7;
  --dark-purple: #5a01a7;
  --golden-yellow: #feac32;
}

body {
  background-color: var(--main-bg-color);
  text-align: center;
}

.title {
  color: var(--light-grey);
  margin: 20px 0;
}

#author-container {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
}

.user-card {
  border-radius: 15px;
  width: 300px;
  height: 350px;
  background-color: var(--light-grey);
  margin: 20px;
}

.user-img {
  width: 150px;
  height: 150px;
  object-fit: cover;
}

.purple-divider {
  background-color: var(--dark-purple);
  width: 100%;
  height: 15px;
}

.author-name {
  margin: 10px;
}

.bio {
  margin: 20px;
}

.error-msg {
  color: var(--light-grey);
}

.btn {
  cursor: pointer;
  width: 200px;
  margin: 10px;
  color: var(--main-bg-color);
  font-size: 14px;
  background-color: var(--golden-yellow);
  background-image: linear-gradient(#fecc4c, #ffac33);
  border-color: var(--golden-yellow);
  border-width: 3px;
}
```

```js
const authorContainer = document.getElementById('author-container');
const loadMoreBtn = document.getElementById('load-more-btn');

fetch('https://cdn.freecodecamp.org/curriculum/news-author-page/authors.json')
  .then((res) => res.json())
  .then((data) => {
    console.log(data);
  })
--fcc-editable-region--

--fcc-editable-region--
```
