balanceofsatoshis/network/gift_callback_error.js
2019-12-07 20:13:28 -08:00

35 lines
852 B
JavaScript

/** Map a gift route error to a callback error
{
err: {
message: <Error Message String>
}
}
@returns
[
<Callback Error Code Number>
<Callback Error Message String>
[Callback Error Context Object>]
]
*/
module.exports = ({err}) => {
const {message} = err;
switch (message) {
case 'NoActiveChannelWithSpecifiedPeer':
return [400, 'SendingGiftRequiresActiveChannelWithPeer'];
case 'NoActiveChannelWithSufficientLocalBalance':
return [400, 'SendingGiftRequiresChanWithSufficientBalance'];
case 'NoActiveChannelWithSufficientRemoteBalance':
return [400, 'SendingGiftRequiresChanWithSomeRemoteBalance'];
case 'NoDirectChannelWithSpecifiedPeer':
return [400, 'SendingGiftRequiresDirectChannelWithPeer'];
default:
return [500, 'UnexpectedErrorDeterminingChanForGift', {err}];
}
};