boson-project / functions

A directory of information and resources for the Boson Project.
Apache License 2.0
6 stars 5 forks source link

[doc] Clarify how http status is controlled by the template #38

Closed drriguz closed 6 months ago

drriguz commented 6 months ago

Current documentation Currently, the document does not mention how http status will be returned. Obviously, for functions using http.ResponseWriter, we can control by res.WriteHeader(200):

func Handle(ctx context.Context, res http.ResponseWriter, req *http.Request) {

However, for cloudevent users, there's no option for controlling http status directly, instead it should be controlled by err error.

func Handle(ctx context.Context, event cloudevents.Event) (resp *cloudevents.Event, err error) {

Accroding to my understanding, the function should return 5xx if an error is returned by Handle. However, I tested the case but still returned 200.

Suggested changes or additions

drriguz commented 6 months ago

It seems that the handler does return 500 if error occurs, however in unit test I got 200.

drriguz commented 6 months ago

Sorry about that, I found it's my mistack. It's working as expected.:p