Skip to content

Commit

Permalink
add error handling to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
theocod3s committed May 2, 2024
1 parent d2af767 commit aa1206d
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,40 @@ Here's how to configure the SDK:

```typescript
const genesiscloud = new GenesisCloudClient({
TOKEN: "your_api_token_here",
TOKEN: process.env.GENESISCLOUD_TOKEN,
});
```

## Examples

### Error handling

Error handling can be done using the try/catch with the async/await syntax. The Genesis Cloud errors are of [this format](/src/core/ApiError.ts).

```typescript
try {
const instance = await genesiscloud.instances.createInstance({
requestBody: {
// ...
},
});
//... do something with instance
} catch (error) {
if (error instanceof ApiError) {
const { code, message } = error.body;
// ... handle genesiscloud error
} else {
// ... handle other errors
}
}
```

### Managing Instances

Listing Instances:

```typescript
const instances = await genesiscloud.instances.listInstances({
const { instances } = await genesiscloud.instances.listInstances({
page: 1,
perPage: 100,
});
Expand Down

0 comments on commit aa1206d

Please sign in to comment.