Repository navigation
Conversation
invoke() call throws if shouldThrowOnError flag is set
- rename HttpError to FunctionsError - pull out status & statusText from FunctionsError - status and statusText are optional
|
Hey @vejja, thank you for the PR ❤️ We couldn't merge this in directly since this would be a breaking change and was a lot going on here. To break it down, the PR proposes these changes automatically adding content types to request request and response transformers |
What kind of change does this PR introduce?
Closes #22
What is the current behavior?
The
invoke()function currently implements the following behavior:fetch()function. This obliges the user to write significant amounts of boilerplate code (e.g. to JSON.parse() the body or set the right headers), as described in issue Callinginvokevia Android OS without specifyingcontent-typeheader results in a failed request #14{ data, error }object wheredatahas already been automagically de-serialized. However the richer underlyingResponseobject from thefetch()call is lost (e.g. status code, headers, etc.), as described in issue shouldThrowOnError does not apply to functions.invoke() #20What is the new behavior?
The new behavior modifies the prototype of
invoke()in accordance with the proposal set out under feature request #22 :invokefunction automagically serializes the body and sets the headers. This reduces the amount of boilerplate for the most common input data typesResponseobject can now be accessed via a thirdoptionsparameter, which provides callback entry points to thefetch()call.Please refer to the accompanying README.md file for further details on the new proposed behavior of
invoke.Additional context
This PR closes #22.
It also fixes #20 and fixes #14.
Notes:
Fetch,Request, andResponseWeb APIs. Previous options that used to be passed as named parameters are now passed according to the prototypes of these APIs.requestheaders are written according to the data type on the way out, and the incoming data type is inferred from reading theresponseheaders on the way back. This is an opinionated convention which I believe covers 99.9% of the use cases of a serverlessfetch()functionality.