@@ -9,7 +9,7 @@ import { readGist, updateGist, deleteGist } from '../state/gists/action-creators
99class Gist extends Component {
1010 render ( ) {
1111 const {
12- readGistStatus, deleteGistStatus, updateGistStatus
12+ readGistStatus, deleteGistStatus, updateGistStatus, gistNotFound
1313 } = this . props ;
1414 const { description, files } = this . state ;
1515
@@ -25,7 +25,8 @@ class Gist extends Component {
2525 return (
2626 < div className = "Gist" >
2727 { readGistStatus . pending && ( 'Loading gist...' ) }
28- { readGistStatus . failed && ( 'There was an error while retrieving this gist' ) }
28+ { readGistStatus . failed && ! gistNotFound && ( 'There was an error while retrieving this gist' ) }
29+ { readGistStatus . failed && gistNotFound && ( 'This gist could not be found.' ) }
2930 { readGistStatus . succeeded && (
3031 < form >
3132 < div >
@@ -213,6 +214,13 @@ function mapStateToProps(state, props) {
213214 // documentation:
214215 // https://redux-resource.js.org/docs/api-reference/get-status.html#tips
215216 const readGistStatus = getStatus ( state , `gists.meta.${ gistId } .readStatus` , true ) ;
217+
218+ // We're using the HTTP Status Code plugin to determine if the error is a 404. Typically,
219+ // if you're using standard HTTP requests in your application, you'll want to include the
220+ // HTTP Status Codes plugin. You can see how this is set up by referring to the gists
221+ // reducer file. For more on the HTTP Status Codes plugin, see the docs at:
222+ // https://redux-resource.js.org/docs/extras/http-status-codes-plugin.html
223+ const gistNotFound = _ . get ( state , `gists.meta.${ gistId } .readStatusCode` ) === 404 ;
216224
217225 // These requests are initiated by a user's action, so we do not pass `treatNullAsPending`
218226 // as `true`. Otherwise, the interface would always display a loading indicator to the user.
@@ -224,6 +232,7 @@ function mapStateToProps(state, props) {
224232 gists,
225233 gistId,
226234 gist,
235+ gistNotFound,
227236 readGistStatus,
228237 deleteGistStatus,
229238 updateGistStatus
0 commit comments