<commit_before>import { put, takeEvery } from 'redux-saga/effects';

import { translate } from '@waldur/i18n';
import * as api from '@waldur/marketplace/common/api';
import { closeModalDialog } from '@waldur/modal/actions';
import { showSuccess, showError } from '@waldur/store/coreSaga';

import * as actions from './actions';
import * as constants from './constants';

function* generateServiceProviderSecretCode(action) {
  const { serviceProvider } = action.payload;
  const successMessage = translate('Service provider API secret code has been generated.');
  const errorMessage = translate('Unable to generate service provider API secret code.');
  try {
    const data = yield api.generateServiceProviderSecretCode(serviceProvider.uuid);
    yield put(actions.secretCodeRegenerateSuccess(data.api_secret_code));
    yield put(closeModalDialog());
    yield put(showSuccess(successMessage));
  } catch (error) {
    yield put(actions.secretCodeRegenerateError());
    yield put(closeModalDialog());
    yield put(showError(errorMessage));
  }
}

function* getServiceProviderSecretCode(action) {
  const { serviceProvider } = action.payload;
  const errorMessage = translate('Unable to get service provider API secret code.');
  try {
    const data = yield api.getServiceProviderSecretCode(serviceProvider.uuid);
    yield put(actions.secretCodeFetchSuccess(data.api_secret_code));
  } catch (error) {
    yield put(showError(errorMessage));
  }
}

export default function*() {
  yield takeEvery(constants.SERVICE_PROVIDER_CODE_REGENERATE_START, generateServiceProviderSecretCode);
  yield takeEvery(constants.SERVICE_PROVIDER_CODE_FETCH_START, getServiceProviderSecretCode);
}<commit_msg>Set service provider's api_secret_code to empty string if server responds with null value.<commit_after>import { put, takeEvery } from 'redux-saga/effects';

import { translate } from '@waldur/i18n';
import * as api from '@waldur/marketplace/common/api';
import { closeModalDialog } from '@waldur/modal/actions';
import { showSuccess, showError } from '@waldur/store/coreSaga';

import * as actions from './actions';
import * as constants from './constants';

function* generateServiceProviderSecretCode(action) {
  const { serviceProvider } = action.payload;
  const successMessage = translate('Service provider API secret code has been generated.');
  const errorMessage = translate('Unable to generate service provider API secret code.');
  try {
    const data = yield api.generateServiceProviderSecretCode(serviceProvider.uuid);
    yield put(actions.secretCodeRegenerateSuccess(data.api_secret_code));
    yield put(closeModalDialog());
    yield put(showSuccess(successMessage));
  } catch (error) {
    yield put(actions.secretCodeRegenerateError());
    yield put(closeModalDialog());
    yield put(showError(errorMessage));
  }
}

function* getServiceProviderSecretCode(action) {
  const { serviceProvider } = action.payload;
  const errorMessage = translate('Unable to get service provider API secret code.');
  try {
    const data = yield api.getServiceProviderSecretCode(serviceProvider.uuid);
    const secretCode = data.api_secret_code ? data.api_secret_code : '';
    yield put(actions.secretCodeFetchSuccess(secretCode));
  } catch (error) {
    yield put(showError(errorMessage));
  }
}

export default function*() {
  yield takeEvery(constants.SERVICE_PROVIDER_CODE_REGENERATE_START, generateServiceProviderSecretCode);
  yield takeEvery(constants.SERVICE_PROVIDER_CODE_FETCH_START, getServiceProviderSecretCode);
}
{'fraction_non_alphanumeric': 0.10453257790368271, 'fraction_numerical': 0.0011331444759206798, 'mean_word_length': 5.751434034416826, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3395501', 'n_tokens_mistral': 960, 'n_tokens_neox': 964, 'n_words': 240}