Skip to content

Commit

Permalink
fix: human readable errors
Browse files Browse the repository at this point in the history
  • Loading branch information
theKashey committed Sep 5, 2020
1 parent e540f5f commit b86bb82
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
14 changes: 7 additions & 7 deletions packages/component/.size-snapshot.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{
"dist/loadable.cjs.js": {
"bundled": 13945,
"minified": 6737,
"gzipped": 2397
"bundled": 14563,
"minified": 7172,
"gzipped": 2534
},
"dist/loadable.esm.js": {
"bundled": 13566,
"minified": 6433,
"gzipped": 2326,
"bundled": 14184,
"minified": 6868,
"gzipped": 2467,
"treeshaked": {
"rollup": {
"code": 276,
"import_statements": 276
},
"webpack": {
"code": 5408
"code": 5744
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions packages/component/src/createLoadable.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ function createLoadable({
function loadable(loadableConstructor, options = {}) {
const ctor = resolveConstructor(loadableConstructor)
const cache = {}

function getCacheKey(props) {
if (options.cacheKey) {
return options.cacheKey(props)
Expand Down Expand Up @@ -167,6 +168,11 @@ function createLoadable({
this.state.result = result
this.state.loading = false
} catch (error) {
console.error('loadable-components: failed to synchronously load component, which expected to be available', {
fileName: ctor.resolve(this.props),
chunkName: ctor.chunkName(this.props),
error: error.message,
});
this.state.error = error
}
}
Expand Down Expand Up @@ -202,6 +208,11 @@ function createLoadable({
return loadedModule
})
.catch(error => {
console.error('loadable-components: failed to asynchronously load component', {
fileName: ctor.resolve(this.props),
chunkName: ctor.chunkName(this.props),
error: error.message,
});
cachedPromise.status = STATUS_REJECTED
throw error
})
Expand Down

0 comments on commit b86bb82

Please sign in to comment.