Skip to content

Commit

Permalink
change throw error to log
Browse files Browse the repository at this point in the history
  • Loading branch information
rykci committed Jan 24, 2023
1 parent b5989af commit f608c7e
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 22 deletions.
3 changes: 1 addition & 2 deletions sdk-test/makePayment.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const { mcsSDK } = require('js-mcs-sdk')
async function main() {
const SOURCE_FILE_UPLOAD_ID = ''
const FILE_SIZE = ''
const MIN_AMOUNT = '' // leave blank for estimated price

const mcs = await mcsSDK.initialize({
privateKey: process.env.PRIVATE_KEY,
Expand All @@ -14,7 +13,7 @@ async function main() {

console.log('version:', mcs.version)

const tx = await mcs.makePayment(SOURCE_FILE_UPLOAD_ID, MIN_AMOUNT, FILE_SIZE)
const tx = await mcs.makePayment(SOURCE_FILE_UPLOAD_ID, FILE_SIZE)
console.log('transaction hash: ' + tx.transactionHash)
}

Expand Down
2 changes: 1 addition & 1 deletion sdk-test/mcs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('MCS SDK', function () {
})

it('Should pay for file', async () => {
await mcs.makePayment(sourceFileUploadId, '', size)
await mcs.makePayment(sourceFileUploadId, size)
})

it('Should mint NFT', async () => {
Expand Down
6 changes: 3 additions & 3 deletions sdk/api/buckets/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ const uploadFile = async (api, jwt, filePath, bucketUid, folder, log) => {

let res = await check(api, jwt, md5.filename, md5.hash, bucketUid, folder)
if (res.status === 'error') {
throw new Error(res.message)
console.error(res.message)
}

await uploadChunks(api, jwt, filePath, md5.filename, md5.hash, log)
Expand Down Expand Up @@ -170,7 +170,7 @@ const downloadFile = async (api, jwt, fileId, outputDirectory) => {
let file = await getFileInfo(api, jwt, fileId)

if (!file) {
throw new Error('file not found')
console.error('file not found')
}

let name = outputDirectory.endsWith('/')
Expand All @@ -181,7 +181,7 @@ const downloadFile = async (api, jwt, fileId, outputDirectory) => {

await fs.promises.writeFile(name, res.data, (err) => {
if (err) {
throw new Error(err.message)
console.error(err.message)
}
})
return { status: 'success' }
Expand Down
2 changes: 1 addition & 1 deletion sdk/api/dealDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const getDealDetail = async (api, jwt, sourceFileUploadId, dealId) => {
config,
)
if (res?.data.status === 'error') {
throw new Error(res.data.message)
console.error(res.data.message)
}
return res.data
} catch (err) {
Expand Down
2 changes: 1 addition & 1 deletion sdk/api/dealList.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const getDealList = async (
config,
)
if (res?.data.status === 'error') {
throw new Error(res.data.message)
console.error(res.data.message)
}
return res?.data
} catch (err) {
Expand Down
2 changes: 1 addition & 1 deletion sdk/api/fileStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const getFileStatus = async (api, jwt, dealId) => {
try {
const res = await axios.get(`${api}/v1/storage/deal/log/${dealId}`, config)
if (res?.data.status === 'error') {
throw new Error(res.data.message)
console.error(res.data.message)
}
return res.data
} catch (err) {
Expand Down
4 changes: 2 additions & 2 deletions sdk/api/makePayment.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const getFilePaymentStatus = async (api, jwt, sourceFileUploadId) => {
config,
)
if (res?.data.status === 'error') {
throw new Error(res.data.message)
console.error(res.data.message)
}

return res?.data
Expand Down Expand Up @@ -45,7 +45,7 @@ const lockToken = async (
let paymentStatus = filePaymentStatus.data.source_file_upload

if (paymentStatus?.is_free || paymentStatus?.status != 'Pending') {
throw new Error('This file is already paid for.')
console.error('This file is already paid for.')
}
const wCid = paymentStatus.w_cid

Expand Down
2 changes: 1 addition & 1 deletion sdk/api/mint.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const postMintInfo = async (api, jwt, mintInfo) => {
)

if (res?.data.status === 'error') {
throw new Error(res.data.message)
console.error(res.data.message)
}

return res?.data
Expand Down
2 changes: 1 addition & 1 deletion sdk/helper/getJwt.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const getJwt = async (api, accessToken, apiKey, loginNetwork) => {
})

if (response?.data.status === 'error') {
throw new Error(response.data.message)
console.error(response.data.message)
}

return response.data?.data
Expand Down
12 changes: 6 additions & 6 deletions sdk/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ class mcsSDK {
} else if (chainName == 'polygon.mumbai') {
api = API.MCS_MUMBAI_API
} else {
throw new Error('unknown chain name')
console.error('unknown chain name')
}

if (!accessToken || !apiKey) {
throw new Error(
console.error(
'Missing access token/API key. Please check your parameters, or visit https://www.multichain.storage/ to generate an API key.',
)
}
Expand Down Expand Up @@ -91,7 +91,7 @@ class mcsSDK {

if (chainId != this.mapChainName(this.chainName)) {
this.web3Initialized = false
throw new Error(
console.error(
`RPC Chain ID (${chainId}) does not match SDK chain name (${this.chainName})`,
)
}
Expand All @@ -112,7 +112,7 @@ class mcsSDK {
*/
upload = async (files, options) => {
if (!this.web3Initialized) {
throw new Error('web3 not setup, call setupWeb3 first')
console.error('web3 not setup, call setupWeb3 first')
}

return await mcsUpload(
Expand All @@ -132,9 +132,9 @@ class mcsSDK {
* @param {string} size - file size in bytes
* @returns {Object} payment transaction response
*/
makePayment = async (sourceFileUploadId, amount, size) => {
makePayment = async (sourceFileUploadId, size, amount = '') => {
if (!this.web3Initialized) {
throw new Error('web3 not setup, call setupWeb3 first')
console.error('web3 not setup, call setupWeb3 first')
}

let tx = await lockToken(
Expand Down
4 changes: 2 additions & 2 deletions sdk/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "js-mcs-sdk",
"version": "4.0.2",
"version": "4.0.3-beta.1",
"description": "A SDK for the MCS service. It provides a convenient interface for working with the MCS API from a web browser or Node.js",
"homepage": "https://github.com/filswan/js-mcs-sdk",
"main": "index.js",
Expand Down

0 comments on commit f608c7e

Please sign in to comment.