Comments (2)
Well, this is what you should do by yourself, because it's up to a developer to handle his errors.
Here's very basic prototype:
// here you can do whatever you want
func myHandler(ctx context.Context, in io.Reader, out io.Writer) error {
return errors.New("blah-blah-error")
}
// here you can handle errors as you wish
func withError(ctx context.Context, in io.Reader, out io.Writer) {
err := myHandler(ctx, in, out)
if err != nil {
fdk.WriteStatus(out, http.StatusInternalServerError)
io.WriteString(out, err.Error())
return
}
fdk.WriteStatus(out, http.StatusOK)
}
func main() {
fdk.Handle(fdk.HandlerFunc(withError))
}
BTW, with this ^ particular approach you're making your code more suitable for testing without asking FDK for test fixtures.
from fdk-go.
yea, for http triggers it makes sense to force users to handle them with their own error codes and errors imo, otherwise we end up imposing some default format on people there (a json message, eg) - managing the divide between invoke and http trigger is kinda weird. for users that do that with http triggers, if they invoke the function with the invoke contract they'll actually break the invoke contract unless they end up using 502 or 504, which kinda stinks, that onus shouldn't be on users - we could likely handle this at the fdk level if we get some > 400, but it's a bit magical. if we add an error to the handler we'd need a contract to define that if a user wrote to the output and returns an error, we'd have to establish precedence there for which gets actually written back out (until we add streaming) - it was something we were trying to avoid anyway. denis' code above maybe helps highlight the issue, if the handler writes to the output and then returns an error it will write both the output and the error (possibly a double error) - say, for somebody that wants to return 503 when their db is down, managing these 2 ways of handling errors is a bit cumbersome (even if we work some magic underneath the covers, it has to be reasoned about by users). open to concrete proposals on this though.
from fdk-go.
Related Issues (18)
- Support changes to Fn JSON format
- fdk-go does not pass protocol info into context of handler function HOT 7
- Unexpected panic during data processing with cloudevents HOT 6
- FDK context should expose similar attributes as any other FDK does HOT 2
- Enhance error prompt while running go fn app locally HOT 4
- override exit codes HOT 3
- [cross-fdk] formalize context contract
- Support JSON protocol
- Update Docs links to point to new Docs repo
- Handling CORS headers inside a function HOT 4
- move readme examples into `_example.go`
- Add a link to https://fnproject.io to the top of the repo
- Add Developer Content to the fdk-go Repo HOT 1
- Tag v1.0.0 HOT 1
- Update Go image on dockerhub HOT 1
- How to organize multiple functions under same repo? HOT 1
- get the request query params HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fdk-go.