示例#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
}
示例#2
0
文件: onedrive.go 项目: dibu28/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 {
		return err
	}
	if errResponse.ErrorInfo.Code == "" {
		errResponse.ErrorInfo.Code = resp.Status
	}
	return errResponse
}
示例#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)
}
示例#4
0
文件: b2.go 项目: 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
}