Skip to content

Commit

Permalink
Merge pull request #263 from roblg/parse-error-response-body
Browse files Browse the repository at this point in the history
Fixed: #261 - error response body needs to be rehydrated
  • Loading branch information
gigabo committed Jun 3, 2016
2 parents 2032f9f + 16527f2 commit ee23e0e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/react-server/core/ReactServerAgent/Cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,17 @@ class CacheEntry {
// once initially, when not loaded, and once again when
// the request arrives

var err = state.err;
if (err) {
err.response = this._rehydrateResponse(err.response);
}

this.url = state.url;
this.requestData = state.requestData;
this.requesters = state.requesters;
this.loaded = state.loaded;
this.res = this._rehydrateResponse(state.res);
this.err = state.err;
this.err = err;

// TODO FIXME: these won't work if the response from the server was an error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,43 @@ describe("ReactServerAgent", () => {
.done();

}));

it("rehydrates response body for non-200 requests", withRlsContext(done => {
var URL = "/error";

ReactServerAgent.get(URL)
.then(res => {
// this is a failure
expect(res).toBeUndefined();
done();
})
.catch(err => {
var cache = ReactServerAgent.cache();
var dehydrated = cache.dehydrate();

// make sure that the cache is empty
ReactServerAgent._clearCache();

cache = ReactServerAgent.cache();

// verify that cache can be rehydrated
cache.rehydrate(dehydrated);

// only one entry; just grab it via index
var entry = cache.dataCache[URL][0];
console.log(entry);
expect(entry).toBeDefined();
expect(entry.err).toBeDefined();
expect(entry.err.response).toBeDefined();

// this will only be defined if rehydrate is working
// properly
expect(entry.err.response.body).toBeDefined();

done();
})
.done();
}));
});

function getSingleDehydratedCacheEntry(dehydratedCache, url) {
Expand Down

0 comments on commit ee23e0e

Please sign in to comment.