Skip to content

Commit

Permalink
Add: error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
danieldanielecki committed Jun 3, 2024
1 parent f96e6a1 commit c744278
Showing 1 changed file with 51 additions and 2 deletions.
53 changes: 51 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,58 @@ <h2>GraphQL Caching (Apollo Client)</h2>
});
</code></pre>
</section>
<section>
<h1>Error Handling</h1>
<table>
<tr>
<th>REST</th>
<th>GraphQL</th>
</tr>
<tr>
<td>Status codes to indicate nature of errors</td>
<td>Error classes (Apollo Server)</td>
</tr>
<tr>
<td>Error messages within response body</td>
<td>Error messages within resolvers</td>
</tr>
<tr>
<td>Well-known middlewares</td>
<td>Can be nested "thanks" to GraphQL queries</td>
</tr>
</table>
</section>
<section>
<h2>Error Handling: REST</h2>
<pre><code>
try {
const resource = await Resource.findByPk(id);
if (resource) {
res.json(resource);
} else {
res.status(404).json({ error: 'Resource not found' });
}
} catch (error) {
res.status(500).json({ error: error.message });
}
</code></pre>
</section>
<section>
<h2>Error Handling: GraphQL</h2>
<pre><code>
try {
const resource = await Resource.findByPk(id);
if (resource) {
return resource;
} else {
throw new UserInputError('Resource not found');
}
} catch (error) {
throw new Error('Failed to fetch resource');
}
</code></pre>
</section>
<!-- <ul>
<li>Database Storage integration with GraphQL (Prisma)</li>
<li>Error Handling - GraphQL returns 200 (OK Status Code) even if errors occured</li>
<li>Global Object Identification</li>
<li>Pagination</li>
<li>Performance</li>
Expand Down

0 comments on commit c744278

Please sign in to comment.