Skip to content

Commit e109bad

Browse files
committed
restructure text and add badges
1 parent f40a93f commit e109bad

1 file changed

Lines changed: 29 additions & 21 deletions

File tree

README.md

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Get-Error
22

3+
![npm version](https://img.shields.io/npm/v/get-error.svg)
4+
![license](https://img.shields.io/npm/l/get-error.svg)
5+
![bundle size](https://img.shields.io/bundlephobia/minzip/get-error)
6+
![typescript](https://img.shields.io/badge/TypeScript-ready-blue.svg)
7+
![tests](https://github.com/everdimension/get-error/actions/workflows/node.js.yml/badge.svg)
8+
39
Safely parse anything into an Error instance
410

511
## Getting Started
@@ -21,27 +27,7 @@ try {
2127
}
2228
```
2329

24-
#### Handy in building User Interaces
25-
26-
```jsx
27-
import React from "react";
28-
import { useQuery } from "@tanstack/react-query";
29-
30-
function App() {
31-
const { data, isError, error } = useQuery({
32-
queryKey: ["data"],
33-
queryFn: async () => {
34-
return Promise.reject(new Response(null, { status: 404 }));
35-
},
36-
});
37-
38-
if (isError) {
39-
// return <p>{error.message}</p> // ❌ NOT safe!
40-
return <p>{getError(error).message}</p>; // ✅ Safe!
41-
}
42-
return <div>{data}</div>;
43-
}
44-
```
30+
That's it!
4531

4632
## Motivation
4733

@@ -90,3 +76,25 @@ try {
9076
console.log(error.message); // "Method not found"
9177
}
9278
```
79+
80+
### Handy in building User Interaces
81+
82+
```jsx
83+
import React from "react";
84+
import { useQuery } from "@tanstack/react-query";
85+
86+
function App() {
87+
const { data, isError, error } = useQuery({
88+
queryKey: ["data"],
89+
queryFn: async () => {
90+
return Promise.reject(new Response(null, { status: 404 }));
91+
},
92+
});
93+
94+
if (isError) {
95+
// return <p>{error.message}</p> // ❌ NOT safe!
96+
return <p>{getError(error).message}</p>; // ✅ Safe!
97+
}
98+
return <div>{data}</div>;
99+
}
100+
```

0 commit comments

Comments
 (0)