Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions gateway/router/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ func (r *Handler) Handle(ctx context.Context, writer http.ResponseWriter, reques
http.Error(writer, err.Error(), http.StatusInternalServerError)
return
}
if aComponent == nil {
http.Error(writer, "component not available", http.StatusServiceUnavailable)
return
}
aResponse, err := r.safelyHandleComponent(ctx, request, aComponent)
if err != nil {
r.writeErrorResponse(ctx, writer, aComponent, err, http.StatusBadRequest)
Expand Down Expand Up @@ -237,6 +241,20 @@ func (r *Handler) writeErrorResponse(ctx context.Context, w http.ResponseWriter,
execCtx.SetError(err)
}
responseStatus := r.responseStatusError(message, anObjectErr)
if aComponent == nil || aComponent.Output.Type.Parameters == nil {
errAsBytes, marshalErr := goJson.Marshal(responseStatus)
if marshalErr != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte("could not parse error message"))
return
}
if execCtx != nil {
execCtx.StatusCode = statusCode
}
w.WriteHeader(statusCode)
w.Write(errAsBytes)
return
}
statusParameter := aComponent.Output.Type.Parameters.LookupByLocation(state.KindOutput, "status")
if statusParameter == nil {
errAsBytes, marshalErr := goJson.Marshal(responseStatus)
Expand Down
11 changes: 11 additions & 0 deletions gateway/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,17 @@ func (r *Service) syncChanges(ctx context.Context, metrics *gmetric.Service, sta
return err
}
r.mux.Lock()
newCount := len(mainRouter.paths)
oldCount := 0
if r.mainRouter != nil {
oldCount = len(r.mainRouter.paths)
}
if newCount < oldCount {
r.mux.Unlock()
fmt.Printf("[INFO]: routers rebuild skipped (new config has %d routes vs %d existing, keeping existing)\n", newCount, oldCount)
return nil
}
fmt.Printf("[INFO]: router replacing old(%d routes) with new(%d routes)\n", oldCount, newCount)
r.mainRouter = mainRouter
r.mux.Unlock()
fmt.Printf("[INFO]: routers rebuild completed after: %s\n", time.Since(start))
Expand Down
4 changes: 3 additions & 1 deletion repository/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ func (p *Provider) Component(ctx context.Context, opts ...Option) (*Component, e
p.mux.Lock()
defer p.mux.Unlock()
if p.control.ChangeKind() == version.ChangeKindDeleted {
//TODO maybe return 404 error
if p.component != nil {
return p.component, nil
}
return nil, nil
}
aComponent, err := p.newComponent(ctx, opts...)
Expand Down
Loading