Skip to content
This repository has been archived by the owner on Aug 12, 2020. It is now read-only.

Commit

Permalink
Error besked fra backend i produktlisten
Browse files Browse the repository at this point in the history
  • Loading branch information
Thom9521 authored and Thom9521 committed Jan 10, 2020
1 parent ce40213 commit 649e1e1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/components/products/ScooterRows.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ function ScooterRows() {
// Anvend query
const { loading, error, data } = useQuery(GET_SCOOTERS);

// Tjekker feljbeskeden og fjerner 'GraphQL error' fra strengen.
const errorHandler = () => {
if (error.message === 'GraphQL error: Ingen elscootere fundet!') {
return error.message.slice(15);
} else {
return 'Error!';
}
};

if (loading)
return (
<tr>
Expand All @@ -31,7 +40,7 @@ function ScooterRows() {
if (error)
return (
<tr>
<td>Error!</td>
<td>{errorHandler()}</td>
</tr>
);

Expand Down
11 changes: 10 additions & 1 deletion src/components/products/SparepartRows.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ function SparepartRows() {
// Anvend query
const { loading, error, data } = useQuery(GET_SPAREPARTS);

// Tjekker feljbeskeden og fjerner 'GraphQL error' fra strengen.
const errorHandler = () => {
if (error.message === 'GraphQL error: Ingen reservedele fundet!') {
return error.message.slice(15);
} else {
return 'Error!';
}
};

if (loading)
return (
<tr>
Expand All @@ -31,7 +40,7 @@ function SparepartRows() {
if (error)
return (
<tr>
<td>Error!</td>
<td>{errorHandler()}</td>
</tr>
);

Expand Down

0 comments on commit 649e1e1

Please sign in to comment.