Skip to content

Commit

Permalink
Return 404 when an object is not found instead of 500
Browse files Browse the repository at this point in the history
  • Loading branch information
jdeppe-pivotal committed Apr 18, 2017
1 parent 17b0e62 commit bb66d40
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/s3proxy/proxy/s3proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,12 @@ func (this *S3Proxy) Handler(w http.ResponseWriter, req *http.Request) {
}

r, err := this.cache.Get(ctx, req.URL.Path)
meta := this.cache.GetMeta(req.URL.Path)

defer r.Close()

if err != nil {
code := http.StatusInternalServerError
if awsErr, ok := err.(awserr.Error); ok {
if awsErr.Code() == "NotFound" {
if awsErr.Code() == "NotFound" || awsErr.Code() == "NoSuchKey" {
code = http.StatusNotFound
} else {
log.Errorf("[%d] AWS Unclassified error: %+v", counter, awsErr)
Expand All @@ -76,6 +74,7 @@ func (this *S3Proxy) Handler(w http.ResponseWriter, req *http.Request) {
return
}

meta := this.cache.GetMeta(req.URL.Path)
if meta != nil {
w.Header().Set("Content-length", fmt.Sprintf("%d", meta.Size))
w.Header().Set("Content-type", meta.ContentType)
Expand Down

0 comments on commit bb66d40

Please sign in to comment.