Example #1
0
// errorHandler parses a non 2xx error response into an error
func errorHandler(resp *http.Response) error {
	// Decode error response
	errResponse := new(api.Error)
	err := rest.DecodeJSON(resp, &errResponse)
	if err != nil {
		fs.Debug(nil, "Couldn't decode error response: %v", err)
	}
	if errResponse.ErrorInfo.Code == "" {
		errResponse.ErrorInfo.Code = resp.Status
	}
	return errResponse
}
Example #2
0
// errorHandler parses a non 2xx error response into an error
func errorHandler(resp *http.Response) error {
	// Decode error response
	errResponse := new(api.Error)
	err := rest.DecodeJSON(resp, &errResponse)
	if err != nil {
		return err
	}
	if errResponse.ErrorInfo.Code == "" {
		errResponse.ErrorInfo.Code = resp.Status
	}
	return errResponse
}
Example #3
0
// waitForJob waits for the job with status in url to complete
func (f *Fs) waitForJob(location string, o *Object) error {
	deadline := time.Now().Add(fs.Config.Timeout)
	for time.Now().Before(deadline) {
		opts := rest.Opts{
			Method:   "GET",
			Path:     location,
			Absolute: true,
		}
		var resp *http.Response
		var err error
		err = f.pacer.Call(func() (bool, error) {
			resp, err = f.srv.Call(&opts)
			return shouldRetry(resp, err)
		})
		if err != nil {
			return err
		}
		if resp.StatusCode == 202 {
			var status api.AsyncOperationStatus
			err = rest.DecodeJSON(resp, &status)
			if err != nil {
				return err
			}
			if status.Status == "failed" || status.Status == "deleteFailed" {
				return errors.Errorf("async operation %q returned %q", status.Operation, status.Status)
			}
		} else {
			var info api.Item
			err = rest.DecodeJSON(resp, &info)
			if err != nil {
				return err
			}
			o.setMetaData(&info)
			return nil
		}
		time.Sleep(1 * time.Second)
	}
	return errors.Errorf("async operation didn't complete after %v", fs.Config.Timeout)
}
Example #4
0
File: b2.go Project: ncw/rclone
// errorHandler parses a non 2xx error response into an error
func errorHandler(resp *http.Response) error {
	// Decode error response
	errResponse := new(api.Error)
	err := rest.DecodeJSON(resp, &errResponse)
	if err != nil {
		fs.Debug(nil, "Couldn't decode error response: %v", err)
	}
	if errResponse.Code == "" {
		errResponse.Code = "unknown"
	}
	if errResponse.Status == 0 {
		errResponse.Status = resp.StatusCode
	}
	if errResponse.Message == "" {
		errResponse.Message = "Unknown " + resp.Status
	}
	return errResponse
}