Exemple #1
0
//Load s3 file
func (fs *S3Source) Load(bucket, filename string) (*bytes.Buffer, error) {
	if strings.HasPrefix(filename, "/") {
		filename = filename[1:]
	}

	res, err := fs.cli.GetObject(&s3.GetObjectInput{
		Bucket: &bucket,
		Key:    &filename,
	})

	if err != nil {
		if err.Error() == "Access Denied" || err.Error() == "The specified key does not exist." {
			return nil, errors2.NewNotFound("not found")
		}

		return nil, err
	}

	defer res.Body.Close()

	buffer := bytes.NewBuffer(make([]byte, 0, *res.ContentLength))
	buffer.ReadFrom(res.Body)

	return buffer, nil
}
Exemple #2
0
func Err(err error) error {
	if err == nil {
		return nil
	}

	if err.Error() == "not found" {
		return errors2.NewNotFound("not found")
	}

	return errors2.NewInternal(err.Error())
}
Exemple #3
0
func Err(err error) error {
	if err == nil {
		return nil
	}

	switch err.Error() {
	case "sql: no rows in result set":
		return errors2.NewNotFound("not found")
	}

	return errors2.NewInternal(err.Error())
}
Exemple #4
0
func TestPanic2(t *testing.T) {
	assert := assert.New(t)
	a := New()

	a.Panic(func(c *C, rcv interface{}) {
		err := rcv.(errors2.Error)
		c.JSON(err.HttpStatus(), err)
	})

	a.GET("/", func(c *C) {
		c.Panic(errors2.NewNotFound("not found"))
		c.String(200, "123")
	})

	r, _ := http.NewRequest("GET", "/", nil)
	w := httptest.NewRecorder()
	a.ServeHTTP(w, r)
	assert.Equal(404, w.Code)
	assert.Equal("{\"message\":\"not found\"}\n", w.Body.String())
}