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

ApiService().use() leads to error in doRequest() #4

Open
noobiek opened this issue Jul 12, 2018 · 0 comments
Open

ApiService().use() leads to error in doRequest() #4

noobiek opened this issue Jul 12, 2018 · 0 comments

Comments

@noobiek
Copy link

noobiek commented Jul 12, 2018

Hi,
I've tried to make a plugin, just like this one https://github.com/apicase/jsonapi
Copy/pasted the code, just changed normalization func. And the doRequest() stopped working.

When mergeOptions() happens the options get "normalized" (not sure what for). After this process the opts array looks like this:
0: {_isNormalized: true, adapter: {…}, payload: {…}, meta: {…}, options: {…}, …}
1: {_isNormalized: true}
...
Then this array is being reduced by this func - return payloadMerger(res, cur.payload);
So the 2nd item (index 1) in the array is breaking the merge logic, as there is no "payload" value.

The error is "Cannot read property 'url' of undefined" in this snippet happens, because "to" is undefined.

merge(from, to) {
const res = Object.assign({}, from, to)
if (to.url !== undefined && from.url !== undefined) {
res.url = to.url[0] === '/' ? to.url : [from.url, to.url].join('/')
}
return res
}

Definig hook locally in ApiService works as intended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant