Example #1
0
func changefeed(logger ctxu.Logger, store storage.MetaStore, imageName, changeID string, records int64) ([]byte, error) {
	changes, err := store.GetChanges(changeID, int(records), imageName)
	if err != nil {
		logger.Errorf("%d GET could not retrieve records: %s", http.StatusInternalServerError, err.Error())
		return nil, errors.ErrUnknown.WithDetail(err)
	}
	out, err := json.Marshal(&changefeedResponse{
		NumberOfRecords: len(changes),
		Records:         changes,
	})
	if err != nil {
		logger.Errorf("%d GET could not json.Marshal changefeedResponse", http.StatusInternalServerError)
		return nil, errors.ErrUnknown.WithDetail(err)
	}
	return out, nil
}
Example #2
0
func serveError(log ctxu.Logger, w http.ResponseWriter, err error) {
	if httpErr, ok := err.(errcode.Error); ok {
		// info level logging for non-5XX http errors
		httpErrCode := httpErr.ErrorCode().Descriptor().HTTPStatusCode
		if httpErrCode >= http.StatusInternalServerError {
			// error level logging for 5XX http errors
			log.Errorf("%s: %s: %v", httpErr.ErrorCode().Error(), httpErr.Message, httpErr.Detail)
		} else {
			log.Infof("%s: %s: %v", httpErr.ErrorCode().Error(), httpErr.Message, httpErr.Detail)
		}
	}
	e := errcode.ServeJSON(w, err)
	if e != nil {
		log.Error(e)
	}
	return
}
Example #3
0
func checkChangefeedInputs(logger ctxu.Logger, s interface{}, r string) (
	store storage.MetaStore, pageSize int64, err error) {

	store, ok := s.(storage.MetaStore)
	if !ok {
		logger.Errorf("%d GET unable to retrieve storage", http.StatusInternalServerError)
		err = errors.ErrNoStorage.WithDetail(nil)
		return
	}
	pageSize, err = strconv.ParseInt(r, 10, 32)
	if err != nil {
		logger.Errorf("%d GET invalid pageSize: %s", http.StatusBadRequest, r)
		err = errors.ErrInvalidParams.WithDetail(
			fmt.Sprintf("invalid records parameter: %s", err.Error()),
		)
		return
	}
	if pageSize == 0 {
		pageSize = notary.DefaultPageSize
	}
	return
}