diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7090358..97529af 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,4 +16,14 @@
* updateAddress(clientId, address) - Update wg-easy client address
### Fix
-* rename(clientId, newName) - now it is not possible to take an existing name
\ No newline at end of file
+* rename(clientId, newName) - now it is not possible to take an existing name
+
+# 1.0.3 (2023-07-20)
+
+### Fix
+
+* rename(clientId, newName) - Added a missed "await"
+
+### Update
+
+* Reworked catching errors. Now, in case of errors, you get an object with the variable "error"
\ No newline at end of file
diff --git a/README.md b/README.md
index c075b3a..6a17a79 100644
--- a/README.md
+++ b/README.md
@@ -10,47 +10,37 @@ Install it from npm:
npm install wg-easy-wrapper
```
+# Error Handling
+
+When a request encounters an error, the response will contain an object with the variable "**error**" This object will provide relevant information about the error
+Example: `{ error: 'The name wg-easy is already taken' }`
+
# Usage
-### Create a new WGEasyWrapper object
+### Create a new instance of the WGEasyWrapper class
```
const WGEasyWrapper = require('wg-easy-wrapper');
-const WGEW = new WGEasyWrapper('https://website.com', 'password_example');
+const wgEasy = new WGEasyWrapper('https://website.com', 'password_example');
```
### Getting the release version
```
-const response = await WGEW.getRelease();
-console.log(response);
-```
-
-```
-7
+await wgEasy.getRelease();
+// 7
```
### Getting a session
```
-const response = await WGEW.getSession();
-console.log(response);
-```
-
-```
-{
- requiresPassword: true,
- authenticated: true
-}
+await wgEasy.getSession();
+// { requiresPassword: true, authenticated: true }
```
### Creating a wg-easy client
```
-const response = await WGEW.create('newClient');
-console.log(response);
-```
-
-```
-{
+await wgEasy.create('newClient');
+/*{
id: '721f6ac2-ab4f-2fz2-v1b4-2gtc93462099',
name: 'newClient',
enabled: true,
@@ -62,32 +52,20 @@ console.log(response);
latestHandshakeAt: null,
transferRx: 0,
transferTx: 0
-}
-
-Or
-
-Сlient with name newClient already exists
+}*/
```
### Deleting a wg-easy client
```
-const response = await WGEW.delete('721f6ac2-ab4f-2fz2-v1b4-2gtc93462099');
-console.log(response);
-```
-
-```
-true
+await wgEasy.delete('721f6ac2-ab4f-2fz2-v1b4-2gtc93462099');
+// { message: 'Deleted' }
```
### Getting wg-easy clients
```
-const response = await WGEW.getClients();
-console.log(response);
-```
-
-```
-[
+await wgEasy.getClients();
+/*[
{
id: 'f2t3bdbh-b340-4e7d-62f7-651a0122bc62',
name: 'testName',
@@ -104,17 +82,14 @@ console.log(response);
{
...
}
-]
+]*/
```
### Getting wg-easy client configuration
```
-const response = await WGEW.getConfig('f2t3bdbh-b340-4e7d-62f7-651a0122bc62');
-console.log(response);
-```
-
-```
+await wgEasy.getConfig('f2t3bdbh-b340-4e7d-62f7-651a0122bc62');
+/*
[Interface]
PrivateKey = ...
Address = 10.8.0.0/24
@@ -127,80 +102,51 @@ PresharedKey = ...
AllowedIPs = 0.0.0.0/0, ::/0
PersistentKeepalive = 0
Endpoint = website.com:51820
+*/
```
### Getting wg-easy client qr-code
```
-const response = await WGEW.getQRCode('f2t3bdbh-b340-4e7d-62f7-651a0122bc62');
-console.log(response);
-```
-
-```
+await wgEasy.getQRCode('f2t3bdbh-b340-4e7d-62f7-651a0122bc62');
+/*
+*/
```
### Enable wg-easy client
```
-const response = await WGEW.enable('f2t3bdbh-b340-4e7d-62f7-651a0122bc62');
-console.log(response);
-```
-
-```
-true
+await wgEasy.enable('f2t3bdbh-b340-4e7d-62f7-651a0122bc62');
+// { message: 'Enabled' }
```
### Disable wg-easy client
```
-const response = await WGEW.disable('f2t3bdbh-b340-4e7d-62f7-651a0122bc62');
-console.log(response);
-```
-
-```
-true
+await wgEasy.disable('f2t3bdbh-b340-4e7d-62f7-651a0122bc62');
+// // { message: 'Disabled' }
```
### Rename wg-easy client
```
-const response = await WGEW.rename('f2t3bdbh-b340-4e7d-62f7-651a0122bc62', 'newName');
-console.log(response);
-```
-
-```
-The name newName is already taken
-
-Or
-
-true
+await wgEasy.rename('f2t3bdbh-b340-4e7d-62f7-651a0122bc62', 'newName');
+// { message: 'Renamed' }
```
### Update wg-easy client address
```
-const response = await WGEW.updateAddress('f2t3bdbh-b340-4e7d-62f7-651a0122bc62', '10.8.0.1');
-console.log(response);
-```
-
-```
-Address is already occupied
-
-Or
-
-true
+await wgEasy.updateAddress('f2t3bdbh-b340-4e7d-62f7-651a0122bc62', '10.8.0.1');
+// { message: 'Address updated' }
```
### Find wg-easy client
```
-const response = await WGEW.find('newName'); || const response = await WGEW.find('f2t3bdbh-b340-4e7d-62f7-651a0122bc62');
-console.log(response);
-```
-
-```
-{
+await wgEasy.find('newName'); // or id or addres
+/*{
id: 'f2t3bdbh-b340-4e7d-62f7-651a0122bc62',
name: 'newName',
enabled: true,
@@ -212,11 +158,7 @@ console.log(response);
latestHandshakeAt: null,
transferRx: 0,
transferTx: 0
-}
-
-Or
-
-Client not found
+}*/
```
# License
diff --git a/index.js b/index.js
index bb2b0ab..61f1b88 100644
--- a/index.js
+++ b/index.js
@@ -1,5 +1,8 @@
const axios = require('axios');
+const idRegex = /.+-.{4}-.{4}-.{4}-.+/;
+const addressRegex = /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/;
+
/**
* WGEasyWrapper class
*/
@@ -36,7 +39,7 @@ class WGEasyWrapper {
const { status } = error.response;
const originalRequest = error.config;
- if (status !== 401) throw new Error(error);
+ if (status !== 401) return Promise.reject(error);
try {
if (authRetryCount < maxAuthRetries) {
@@ -55,12 +58,15 @@ class WGEasyWrapper {
/**
* Getting the release version
- * @returns {Promise}
+ * @returns {Promise