improve error handling; pass filePath to publish.js explicitly
This commit is contained in:
parent
6aeee63d85
commit
593d748bc0
7 changed files with 40 additions and 15 deletions
|
@ -2,17 +2,14 @@ import { connect } from 'react-redux';
|
|||
import { onHandleShowHomepage } from '../../actions/show';
|
||||
import View from './view';
|
||||
|
||||
<<<<<<< HEAD
|
||||
const mapStateToProps = ({ show, site, channel }) => {
|
||||
const mapStateToProps = ({ show, site, channel, publish }) => {
|
||||
return {
|
||||
error : show.request.error,
|
||||
requestType: show.request.type,
|
||||
homeChannel: site.publishOnlyApproved && !channel.loggedInChannel.name ? `${site.approvedChannels[0].name}:${site.approvedChannels[0].longId}` : null,
|
||||
isUpdate : publish.isUpdate,
|
||||
};
|
||||
};
|
||||
=======
|
||||
const mapStateToProps = props => ({ isUpdate: props.publish.isUpdate });
|
||||
>>>>>>> clear publish and edit pages based on publish.isUpdate
|
||||
|
||||
const mapDispatchToProps = {
|
||||
onHandleShowHomepage,
|
||||
|
|
|
@ -72,7 +72,12 @@ function * publishFile (action) {
|
|||
},
|
||||
});
|
||||
}
|
||||
return history.push(`/${success.data.claimId}/${success.data.name}`);
|
||||
if (success.data.claimId) {
|
||||
return history.push(`/${success.data.claimId}/${success.data.name}`);
|
||||
} else {
|
||||
// this returns to the homepage, needs work
|
||||
return yield put(updatePublishStatus(publishStates.FAILED, 'ERROR'));
|
||||
}
|
||||
}
|
||||
if (loadStart) {
|
||||
yield put(updatePublishStatus(publishStates.LOAD_START, null));
|
||||
|
|
|
@ -83,7 +83,7 @@ const claimPublish = ({ body, files, headers, ip, originalUrl, user, tor }, res)
|
|||
publish(thumbnailPublishParams, thumbnailFileName, thumbnailFileType);
|
||||
}
|
||||
// publish the asset
|
||||
return publish(publishParams, fileName, fileType);
|
||||
return publish(publishParams, fileName, fileType, filePath);
|
||||
})
|
||||
.then(claimData => {
|
||||
logger.debug('Publish success >', claimData);
|
||||
|
|
|
@ -5,11 +5,10 @@ const { createFileRecordDataAfterPublish } = require('../../../../models/utils/c
|
|||
const { createClaimRecordDataAfterPublish } = require('../../../../models/utils/createClaimRecordData.js');
|
||||
const deleteFile = require('./deleteFile.js');
|
||||
|
||||
const publish = async (publishParams, fileName, fileType) => {
|
||||
const publish = async (publishParams, fileName, fileType, filePath) => {
|
||||
let publishResults;
|
||||
let channel;
|
||||
let fileRecord;
|
||||
let filePath = publishParams.file_path;
|
||||
let newFile = Boolean(filePath);
|
||||
|
||||
try {
|
||||
|
@ -53,9 +52,18 @@ const publish = async (publishParams, fileName, fileType) => {
|
|||
|
||||
return claimRecord;
|
||||
} catch (err) {
|
||||
logger.error('PUBLISH ERROR', err);
|
||||
await deleteFile(filePath);
|
||||
return err;
|
||||
// parse daemon response when err is a string
|
||||
// this needs work
|
||||
logger.info('publish/publish err:', err);
|
||||
const error = typeof err === 'string' ? JSON.parse(err) : err;
|
||||
if (filePath) {
|
||||
await deleteFile(filePath);
|
||||
}
|
||||
const message = error.error && error.error.message ? error.error.message : 'Unknown publish error';
|
||||
return {
|
||||
error: true,
|
||||
message,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -123,9 +123,17 @@ const claimUpdate = ({ body, files, headers, ip, originalUrl, user, tor }, res)
|
|||
publishParams['thumbnail'] = `${details.host}/${channelName}:${channelId}/${name}-thumb.jpg`;
|
||||
}
|
||||
|
||||
return publish(publishParams, fileName, fileType);
|
||||
const fp = files && files.file && files.file.path ? files.file.path : undefined;
|
||||
return publish(publishParams, fileName, fileType, fp);
|
||||
})
|
||||
.then(claimData => {
|
||||
// this may need to happen in ../publish/index.js as well
|
||||
if (claimData.error) {
|
||||
res.status(400).json({
|
||||
success: false,
|
||||
message: claimData.message,
|
||||
});
|
||||
}
|
||||
const {claimId} = claimData;
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
|
|
|
@ -2,6 +2,7 @@ const axios = require('axios');
|
|||
const logger = require('winston');
|
||||
const { apiHost, apiPort, getTimeout } = require('@config/lbryConfig');
|
||||
const lbrynetUri = 'http://' + apiHost + ':' + apiPort;
|
||||
const db = require('../models');
|
||||
const { chooseGaLbrynetPublishLabel, sendGATimingEvent } = require('../utils/googleAnalytics.js');
|
||||
const handleLbrynetResponse = require('./utils/handleLbrynetResponse.js');
|
||||
const { publishing } = require('@config/siteConfig');
|
||||
|
@ -90,7 +91,13 @@ module.exports = {
|
|||
})
|
||||
.then(({ data }) => {
|
||||
sendGATimingEvent('lbrynet', 'resolveUri', 'RESOLVE', gaStartTime, Date.now());
|
||||
if (data.result[uri].error) { // check for errors
|
||||
if (Object.keys(data.result).length === 0 && data.result.constructor === Object) {
|
||||
// workaround for daemon returning empty result object
|
||||
// https://github.com/lbryio/lbry/issues/1485
|
||||
db.Claim.findOne({ where: { claimId: uri.split('#')[1] } })
|
||||
.then(() => reject('This claim has not yet been confirmed on the LBRY blockchain'))
|
||||
.catch(() => reject(`Claim ${uri} does not exist`));
|
||||
} else if (data.result[uri].error) { // check for errors
|
||||
reject(data.result[uri].error);
|
||||
} else { // if no errors, resolve
|
||||
resolve(data.result[uri]);
|
||||
|
|
|
@ -28,7 +28,7 @@ async function createFileRecordDataAfterGet (resolveResult, getResult) {
|
|||
filePath,
|
||||
fileType,
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
async function createFileRecordDataAfterPublish (fileName, fileType, publishParams, publishResults) {
|
||||
const {
|
||||
|
|
Loading…
Reference in a new issue