Skip to content

Commit

Permalink
Forward status code from Pre-create http hook
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverpool authored Feb 2, 2019
1 parent fa58f91 commit d6a9849
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions cmd/tusd/cli/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ type hookDataStore struct {

func (store hookDataStore) NewUpload(info tusd.FileInfo) (id string, err error) {
if output, err := invokeHookSync(HookPreCreate, info, true); err != nil {
return "", fmt.Errorf("pre-create hook failed: %s\n%s", err, string(output))
hookErr := fmt.Errorf("pre-create hook failed: %s\n%s", err, string(output))
if statusErr, ok := err.(tusd.HTTPError); ok {
return "", tusd.NewHTTPError(hookErr, statusErr.StatusCode())
}
return "", hookErr
}
return store.DataStore.NewUpload(info)
}
Expand Down Expand Up @@ -144,7 +148,7 @@ func invokeHttpHook(name string, typ HookType, info tusd.FileInfo, captureOutput
}

if resp.StatusCode >= http.StatusBadRequest {
return body, fmt.Errorf("endpoint returned: %s\n%s", resp.Status, body)
return body, tusd.NewHTTPError(fmt.Errorf("endpoint returned: %s\n%s", resp.Status, body), resp.StatusCode)
}

if captureOutput {
Expand Down

0 comments on commit d6a9849

Please sign in to comment.