Last active
November 29, 2016 23:12
-
-
Save bessey/926cdb3e383b406e7f546c6f4dd55a8a to your computer and use it in GitHub Desktop.
Apollo error workaround
This file contains hidden or 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
| import React, { Component, PropTypes } from "react" | |
| // Fixes a silly bug in Apollo where certain errors are not propagated to the console | |
| const throwApolloError = function(WrappedComponent) { | |
| return class ApolloErrorThrower extends Component { | |
| static propTypes = { | |
| data: PropTypes.shape({ | |
| error: PropTypes.object | |
| }) | |
| } | |
| render () { | |
| let error = null | |
| if (this.props.data) { | |
| error = this.props.data.error | |
| } | |
| if (error) { | |
| throw error | |
| } else { | |
| return <WrappedComponent {...this.props}/> | |
| } | |
| } | |
| } | |
| } | |
| export default throwApolloError |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment