Skip to content

Commit

Permalink
Merge pull request #53 from LucaDiba/changeset-release/main
Browse files Browse the repository at this point in the history
Version Packages
  • Loading branch information
LucaDiba authored Feb 21, 2024
2 parents 0b892be + f05261b commit 81b7b6f
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 94 deletions.
93 changes: 0 additions & 93 deletions .changeset/new-rocks-sing.md

This file was deleted.

94 changes: 94 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,99 @@
# @lucadiba/satispay-client

## 1.0.0

### Major Changes

- d66664d: # Breaking changes

## Errors

Before this change, the library returned the following object for all the Client requests:

```typescript
const paymentResponse = await satispay.payments.create({
flow: "MATCH_CODE",
amountUnit: 100,
currency: "EUR",
});

/**
* paymentResponse: {
* success: true,
* data: {
* ...
* }
* } | {
* success: false,
* error: {
* ...
* }
* }
*/

if (paymentResponse.success) {
const payment = paymentResponse.data;

// Save the payment id
const paymentId = payment.id;

// Redirect the user to the redirectUrl
const redirectUrl = payment.redirect_url;

// ...
} else {
// Handle the error
const error = paymentResponse.error;
}
```

After this change, the library will directly throw an error if the request fails.
If the request is successful, the library will return the successful response.

```typescript
try {
const payment = await satispay.payments.create({
flow: "MATCH_CODE",
amountUnit: 100,
currency: "EUR",
});

// Save the payment id
const paymentId = payment.id;

// Redirect the user to the redirectUrl
const redirectUrl = payment.redirect_url;

// ...
} catch (error) {
// Handle the error
}
```

The error type `SatispayError` has been introduced. It extends the `Error` class and has the following properties:

- `name: string` - The error name
- `message: string` - The error message
- `code: string` - The error code
- `status: number` - The HTTP status code

It is possible to check the error type using the `isSatispayError` utility function.
If the result is true, the error type `SatispayError` is automatically inferred.

```typescript
import { SatispayError } from "@lucadiba/satispay-client";

try {
// ...
} catch (error) {
if (SatispayError.isSatispayError(error)) {
// The SatispayError type is automatically inferred to the error variable
} else {
// The type of the error variable is unknown
}
}
```

## 0.1.6

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@lucadiba/satispay-client",
"license": "MIT",
"version": "0.1.6",
"version": "1.0.0",
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
Expand Down

0 comments on commit 81b7b6f

Please sign in to comment.