-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved error view handling, returning missing component in dev, cus…
…tom error always if declared
- Loading branch information
1 parent
f3179cc
commit b771834
Showing
8 changed files
with
102 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,29 @@ | ||
import React from 'react' | ||
import idx from 'idx' | ||
import PropTypes from 'prop-types' | ||
import has from 'lodash/has' | ||
import DefaultError from './default-error' | ||
import MissingView from './missing-view' | ||
|
||
const RenderError = ({ config, data }) => { | ||
const RenderError = ({ config, response, missing }) => { | ||
// render custom error or default if custom error not declared | ||
let ErrorView = has(config, 'components.CustomError') ? | ||
let ErrorView = idx(config, _ => _.components.CustomError) ? | ||
config.components.CustomError : | ||
DefaultError | ||
// always render missing view in development | ||
if (__DEV__) { | ||
ErrorView = () => MissingView(data) | ||
// render missing component only in DEV | ||
if (__DEV__ && missing) { | ||
ErrorView = MissingView | ||
response = { | ||
message: 'Missing component' | ||
} | ||
} | ||
// return one of the error views | ||
return <ErrorView /> | ||
return <ErrorView {...response} /> | ||
} | ||
|
||
RenderError.propTypes = { | ||
config: PropTypes.object, | ||
data: PropTypes.any | ||
missing: PropTypes.bool, | ||
response: PropTypes.object | ||
} | ||
|
||
export default RenderError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters