show network error in in imagepicker

main
Mike Fix 6 years ago
parent 5badd2fbbb
commit 8087f0222f

@ -102,13 +102,22 @@ export default class extends React.Component {
handleURLInput(e) { handleURLInput(e) {
e.preventDefault() e.preventDefault()
const url = e.target[0].value const url = e.target[0].value
return downloadThumbnailImage({ url }).then(({ dataURL }) => return downloadThumbnailImage({ url })
.then(({ dataURL }) =>
this.props.onChange({ this.props.onChange({
backgroundImage: dataURL, backgroundImage: dataURL,
backgroundImageSelection: null, backgroundImageSelection: null,
photographer: null photographer: null
}) })
) )
.catch(err => {
if (err.message.indexOf('Network Error') > -1) {
this.setState({
error:
'Fetching the image failed. This is probably a CORS-related issue. You can either enable CORS in your browser, or use another image.'
})
}
})
} }
selectMode(mode) { selectMode(mode) {
@ -167,6 +176,7 @@ export default class extends React.Component {
<button type="submit">Upload</button> <button type="submit">Upload</button>
</form> </form>
)} )}
{this.state.error && <span className="error">{this.state.error}</span>}
</div> </div>
<hr /> <hr />
<div className="random-image"> <div className="random-image">
@ -242,6 +252,11 @@ export default class extends React.Component {
margin-bottom: 0; margin-bottom: 0;
margin-top: 0; margin-top: 0;
} }
.error {
color: red;
margin-top: 8px;
}
`} `}
</style> </style>
</div> </div>

Loading…
Cancel
Save