Remove some (unnecessary) error handling
This commit is contained in:
parent
f4ccd53ba5
commit
ea62277eb8
|
@ -1,7 +1,6 @@
|
||||||
package cli
|
package cli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -162,11 +161,6 @@ func invokeHookSync(typ hooks.HookType, event handler.HookEvent) (httpRes handle
|
||||||
|
|
||||||
httpRes = hookRes.HTTPResponse
|
httpRes = hookRes.HTTPResponse
|
||||||
|
|
||||||
if hookRes.Error != "" {
|
|
||||||
// TODO: Is this actually useful?
|
|
||||||
return httpRes, errors.New(hookRes.Error)
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the hook response includes the instruction to reject the upload, reuse the error code
|
// If the hook response includes the instruction to reject the upload, reuse the error code
|
||||||
// and message from ErrUploadRejectedByServer, but also include custom HTTP response values
|
// and message from ErrUploadRejectedByServer, but also include custom HTTP response values
|
||||||
if typ == hooks.HookPreCreate && hookRes.RejectUpload {
|
if typ == hooks.HookPreCreate && hookRes.RejectUpload {
|
||||||
|
|
|
@ -17,10 +17,6 @@ type HookRequest struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type HookResponse struct {
|
type HookResponse struct {
|
||||||
// Error indicates whether a fault occurred while processing the hook request.
|
|
||||||
// If Error is an empty string, no fault is assumed.
|
|
||||||
Error string
|
|
||||||
|
|
||||||
HTTPResponse handler.HTTPResponse
|
HTTPResponse handler.HTTPResponse
|
||||||
|
|
||||||
RejectUpload bool
|
RejectUpload bool
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
package hooks
|
package hooks
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"log"
|
"log"
|
||||||
"net/rpc"
|
"net/rpc"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
|
||||||
"github.com/hashicorp/go-plugin"
|
"github.com/hashicorp/go-plugin"
|
||||||
"github.com/tus/tusd/pkg/handler"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO: When the tusd process stops, the plugin does not get properly killed
|
// TODO: When the tusd process stops, the plugin does not get properly killed
|
||||||
|
@ -67,13 +65,6 @@ var pluginMap = map[string]plugin.Plugin{
|
||||||
"hookHandler": &HookHandlerPlugin{},
|
"hookHandler": &HookHandlerPlugin{},
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Explain, mention that it is internal only
|
|
||||||
// TODO: Do we actually need this? Maybe not...
|
|
||||||
type InvokeHookRPCAnswer struct {
|
|
||||||
HookResponse HookResponse
|
|
||||||
TusdError *handler.Error // Why is TusdError a pointer
|
|
||||||
}
|
|
||||||
|
|
||||||
// Here is an implementation that talks over RPC
|
// Here is an implementation that talks over RPC
|
||||||
type HookHandlerRPC struct{ client *rpc.Client }
|
type HookHandlerRPC struct{ client *rpc.Client }
|
||||||
|
|
||||||
|
@ -83,19 +74,9 @@ func (g *HookHandlerRPC) Setup() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *HookHandlerRPC) InvokeHook(req HookRequest) (HookResponse, error) {
|
func (g *HookHandlerRPC) InvokeHook(req HookRequest) (res HookResponse, err error) {
|
||||||
var answer InvokeHookRPCAnswer
|
err = g.client.Call("Plugin.InvokeHook", req, &res)
|
||||||
err := g.client.Call("Plugin.InvokeHook", req, &answer)
|
return res, err
|
||||||
fmt.Printf("Client: %#v\n", answer.TusdError)
|
|
||||||
if err != nil {
|
|
||||||
return answer.HookResponse, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if answer.TusdError != nil {
|
|
||||||
return answer.HookResponse, *answer.TusdError
|
|
||||||
}
|
|
||||||
|
|
||||||
return answer.HookResponse, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Here is the RPC server that HookHandlerRPC talks to, conforming to
|
// Here is the RPC server that HookHandlerRPC talks to, conforming to
|
||||||
|
@ -109,21 +90,9 @@ func (s *HookHandlerRPCServer) Setup(args interface{}, resp *interface{}) error
|
||||||
return s.Impl.Setup()
|
return s.Impl.Setup()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *HookHandlerRPCServer) InvokeHook(args HookRequest, answer *InvokeHookRPCAnswer) error {
|
func (s *HookHandlerRPCServer) InvokeHook(args HookRequest, resp *HookResponse) (err error) {
|
||||||
resp, err := s.Impl.InvokeHook(args)
|
*resp, err = s.Impl.InvokeHook(args)
|
||||||
if err != nil {
|
return err
|
||||||
|
|
||||||
if tusdErr, ok := err.(handler.Error); ok {
|
|
||||||
answer.TusdError = &tusdErr
|
|
||||||
return nil
|
|
||||||
} else {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
answer.HookResponse = resp
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is the implementation of plugin.Plugin so we can serve/consume this
|
// This is the implementation of plugin.Plugin so we can serve/consume this
|
||||||
|
|
Loading…
Reference in New Issue