Giter Club home page Giter Club logo

Comments (2)

denismakogon avatar denismakogon commented on September 17, 2024

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.

rdallman avatar rdallman commented on September 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.