Skip to content

Commit e42679e

Browse files
committed
move catch pinning error to correct place
1 parent ae07144 commit e42679e

File tree

5 files changed

+22
-14
lines changed

5 files changed

+22
-14
lines changed

src/deploy.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -213,15 +213,7 @@ async function unpin (dnsServices, pinServices, logger) {
213213

214214
for (const pinProvider of pinServices) {
215215
logger.info(`Unpinning ${cidToUnpin} from ${pinProvider.displayName}`)
216-
try {
217-
await pinProvider.unpinCid(cidToUnpin)
218-
} catch (e) {
219-
if (e.name === 'HTTPError' && e.message === 'not pinned or pinned indirectly') {
220-
logger.info(`${cidToUnpin} not pinned to ${pinProvider.displayName}, moving forward`)
221-
} else {
222-
throw (e)
223-
}
224-
}
216+
await pinProvider.unpinCid(cidToUnpin, logger)
225217
}
226218
}
227219

src/pinners/ipfs-cluster.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const { getDirFormData } = require('./utils')
88
/**
99
* @typedef {import('./types').IPFSClusterOptions} IPFSClusterOptions
1010
* @typedef {import('./types').PinDirOptions} PinDirOptions
11+
* @typedef {import('../types').Logger} Logger
1112
*/
1213

1314
class IpfsCluster {
@@ -75,8 +76,9 @@ class IpfsCluster {
7576

7677
/**
7778
* @param {string} cid
79+
* @param {Logger} logger
7880
*/
79-
async unpinCid (cid) {
81+
async unpinCid (cid, logger) {
8082
throw new Error('unpinCid not implemented in IpfsCluster')
8183
}
8284

src/pinners/ipfs-node.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const path = require('path')
77
/**
88
* @typedef {import('ipfs-http-client').Options} IpfsOptions
99
* @typedef {import('./types').PinDirOptions} PinDirOptions
10+
* @typedef {import('../types').Logger} Logger
1011
*/
1112

1213
class IpfsNode {
@@ -45,9 +46,18 @@ class IpfsNode {
4546

4647
/**
4748
* @param {string} cid
49+
* @param {Logger} logger
4850
*/
49-
async unpinCid (cid) {
50-
await this.ipfs.pin.rm(cid)
51+
async unpinCid (cid, logger) {
52+
try {
53+
await this.ipfs.pin.rm(cid)
54+
} catch (e) {
55+
if (e.name === 'HTTPError' && e.message === 'not pinned or pinned indirectly') {
56+
logger.info(`${cid} not pinned to ${this.displayName}, moving forward`)
57+
} else {
58+
throw (e)
59+
}
60+
}
5161
}
5262

5363
/**

src/pinners/pinata.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const { getDirFormData } = require('./utils')
77
/**
88
* @typedef {import('./types').PinataOptions} PinataOptions
99
* @typedef {import('./types').PinDirOptions} PinDirOptions
10+
* @typedef {import('../types').Logger} Logger
1011
*/
1112

1213
const MAX_RETRIES = 3
@@ -93,8 +94,9 @@ class Pinata {
9394

9495
/**
9596
* @param {string} cid
97+
* @param {Logger} logger
9698
*/
97-
async unpinCid (cid) {
99+
async unpinCid (cid, logger) {
98100
throw new Error('unpinCid not implemented in Pinata')
99101
}
100102

src/pinners/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { Logger } from '../types'
2+
13
export interface PinDirOptions {
24
tag?: string
35
hidden?: boolean
@@ -6,7 +8,7 @@ export interface PinDirOptions {
68
export interface PinningService {
79
pinDir: (dir: string, options: PinDirOptions|undefined) => Promise<string>
810
pinCid: (cid: string, tag: string|undefined) => void
9-
unpinCid: (cid: string) => void
11+
unpinCid: (cid: string, logger: Logger) => void
1012
gatewayUrl: (cid: string) => string
1113
displayName: string
1214
}

0 commit comments

Comments
 (0)