Skip to content

Commit f5719ec

Browse files
Feature: (Process and get receipt, Handle error 422)
1 parent ab43453 commit f5719ec

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

lib/Thepeer.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,39 @@ class ThePeer {
157157
Helper.processError(e)
158158
}
159159
}
160+
161+
/**
162+
* @memberof ThePeer
163+
* @param {string} receipt - The reference returned to your receiptURL via the Chain SDK
164+
* @param {boolean} insufficientFunds - Status of user funds
165+
* @returns {JSON} A JSON response containing the details of the user
166+
*/
167+
async processSendReceipt (receipt, insufficientFunds) {
168+
try {
169+
const response = await this.request.post(`/send/${receipt}`, {
170+
insufficient_funds: insufficientFunds
171+
})
172+
173+
return response.data
174+
} catch (e) {
175+
Helper.processError(e)
176+
}
177+
}
178+
179+
/**
180+
* @memberof ThePeer
181+
* @param {string} receipt - The reference returned to your receiptURL via the Chain SDK
182+
* @returns {JSON} A JSON response containing the details of the user
183+
*/
184+
async getSendReceipt (receipt) {
185+
try {
186+
const response = await this.request.get(`/send/${receipt}`)
187+
188+
return response.data
189+
} catch (e) {
190+
Helper.processError(e)
191+
}
192+
}
160193
}
161194

162195
module.exports = ThePeer

lib/utils/Helper/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const NotAcceptableError = require('../errors/NotAcceptableError')
55
const ServerError = require('../errors/ServerError')
66
const ServiceUnavailableError = require('../errors/ServiceUnavailableError')
77
const UnauthorizedError = require('../errors/UnauthorizedError')
8+
const InvalidPayloadError = require('../errors/InvalidPayloadError')
89

910
/**
1011
* @class Helper
@@ -28,6 +29,7 @@ class Helper {
2829
* @memberof Helper
2930
*/
3031
static processError (error) {
32+
const errordata = error.response.data.error
3133
switch (error.response.status) {
3234
case 401:
3335
throw new UnauthorizedError({ message: error.response.data.message })
@@ -37,6 +39,10 @@ class Helper {
3739
throw new InvalidResourceError({ message: error.response.data.message })
3840
case 406:
3941
throw new NotAcceptableError({ message: error.response.data.message })
42+
case 422 : Object.keys(errordata).forEach((key) => {
43+
throw new InvalidPayloadError({ message: errordata[key] })
44+
})
45+
break
4046
case 503:
4147
throw new ServiceUnavailableError({ message: error.response.data.message })
4248
default:

0 commit comments

Comments
 (0)