improve error handling; pass filePath to publish.js explicitly

This commit is contained in:
Travis Eden 2018-10-04 10:26:42 -04:00
parent 6aeee63d85
commit 593d748bc0
7 changed files with 40 additions and 15 deletions

View file

@ -2,17 +2,14 @@ import { connect } from 'react-redux';
import { onHandleShowHomepage } from '../../actions/show'; import { onHandleShowHomepage } from '../../actions/show';
import View from './view'; import View from './view';
<<<<<<< HEAD const mapStateToProps = ({ show, site, channel, publish }) => {
const mapStateToProps = ({ show, site, channel }) => {
return { return {
error : show.request.error, error : show.request.error,
requestType: show.request.type, requestType: show.request.type,
homeChannel: site.publishOnlyApproved && !channel.loggedInChannel.name ? `${site.approvedChannels[0].name}:${site.approvedChannels[0].longId}` : null, 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 = { const mapDispatchToProps = {
onHandleShowHomepage, onHandleShowHomepage,

View file

@ -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) { if (loadStart) {
yield put(updatePublishStatus(publishStates.LOAD_START, null)); yield put(updatePublishStatus(publishStates.LOAD_START, null));

View file

@ -83,7 +83,7 @@ const claimPublish = ({ body, files, headers, ip, originalUrl, user, tor }, res)
publish(thumbnailPublishParams, thumbnailFileName, thumbnailFileType); publish(thumbnailPublishParams, thumbnailFileName, thumbnailFileType);
} }
// publish the asset // publish the asset
return publish(publishParams, fileName, fileType); return publish(publishParams, fileName, fileType, filePath);
}) })
.then(claimData => { .then(claimData => {
logger.debug('Publish success >', claimData); logger.debug('Publish success >', claimData);

View file

@ -5,11 +5,10 @@ const { createFileRecordDataAfterPublish } = require('../../../../models/utils/c
const { createClaimRecordDataAfterPublish } = require('../../../../models/utils/createClaimRecordData.js'); const { createClaimRecordDataAfterPublish } = require('../../../../models/utils/createClaimRecordData.js');
const deleteFile = require('./deleteFile.js'); const deleteFile = require('./deleteFile.js');
const publish = async (publishParams, fileName, fileType) => { const publish = async (publishParams, fileName, fileType, filePath) => {
let publishResults; let publishResults;
let channel; let channel;
let fileRecord; let fileRecord;
let filePath = publishParams.file_path;
let newFile = Boolean(filePath); let newFile = Boolean(filePath);
try { try {
@ -53,9 +52,18 @@ const publish = async (publishParams, fileName, fileType) => {
return claimRecord; return claimRecord;
} catch (err) { } catch (err) {
logger.error('PUBLISH ERROR', err); // parse daemon response when err is a string
await deleteFile(filePath); // this needs work
return err; 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,
};
} }
}; };

View file

@ -123,9 +123,17 @@ const claimUpdate = ({ body, files, headers, ip, originalUrl, user, tor }, res)
publishParams['thumbnail'] = `${details.host}/${channelName}:${channelId}/${name}-thumb.jpg`; 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 => { .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; const {claimId} = claimData;
res.status(200).json({ res.status(200).json({
success: true, success: true,

View file

@ -2,6 +2,7 @@ const axios = require('axios');
const logger = require('winston'); const logger = require('winston');
const { apiHost, apiPort, getTimeout } = require('@config/lbryConfig'); const { apiHost, apiPort, getTimeout } = require('@config/lbryConfig');
const lbrynetUri = 'http://' + apiHost + ':' + apiPort; const lbrynetUri = 'http://' + apiHost + ':' + apiPort;
const db = require('../models');
const { chooseGaLbrynetPublishLabel, sendGATimingEvent } = require('../utils/googleAnalytics.js'); const { chooseGaLbrynetPublishLabel, sendGATimingEvent } = require('../utils/googleAnalytics.js');
const handleLbrynetResponse = require('./utils/handleLbrynetResponse.js'); const handleLbrynetResponse = require('./utils/handleLbrynetResponse.js');
const { publishing } = require('@config/siteConfig'); const { publishing } = require('@config/siteConfig');
@ -90,7 +91,13 @@ module.exports = {
}) })
.then(({ data }) => { .then(({ data }) => {
sendGATimingEvent('lbrynet', 'resolveUri', 'RESOLVE', gaStartTime, Date.now()); 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); reject(data.result[uri].error);
} else { // if no errors, resolve } else { // if no errors, resolve
resolve(data.result[uri]); resolve(data.result[uri]);

View file

@ -28,7 +28,7 @@ async function createFileRecordDataAfterGet (resolveResult, getResult) {
filePath, filePath,
fileType, fileType,
}; };
}; }
async function createFileRecordDataAfterPublish (fileName, fileType, publishParams, publishResults) { async function createFileRecordDataAfterPublish (fileName, fileType, publishParams, publishResults) {
const { const {