Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed: #261 - error response body needs to be rehydrated #263

Merged
merged 1 commit into from
Jun 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice.


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

function getSingleDehydratedCacheEntry(dehydratedCache, url) {
Expand Down