Repository: hasura/graphql-engine
File: console/src/components/Services/Data/utils.js (JavaScript)

Code before:
FROM
  pg_class
WHERE
  oid = (quote_ident('${schemaName}') || '.' || quote_ident('${tableName}'))::regclass::oid
  AND relname = '${tableName}';
`;
};

export const isColTypeString = colType =>
  ['text', 'varchar', 'char', 'bpchar', 'name'].includes(colType);

export const cascadeUpQueries = (upQueries = []) =>
  upQueries.map((i = {}) => {
    if (i.type === 'run_sql' || i.type === 'untrack_table') {
      return {
        ...i,
        args: {
          ...i.args,
          cascade: true,
        },
      };
    }
    return i;
  });

export const getRetryStatus = (isRetry, err = {}) => {
  const defaultRes = { canRetry: false, errorObj: err };
  if (isRetry) return defaultRes;

  if (err.code == ERROR_CODES.dependencyError.code) {
    // direct dependency error
    return { canRetry: true, errorObj: err };
  } else if (err.code == ERROR_CODES.dataApiError.code) {
    // message is coming as error, further parssing willbe based on message key
    const actualError = isJsonString(err.message)
      ? JSON.parse(err.message)
      : {};
    if (actualError.code == ERROR_CODES.dependencyError.code) {
      return {
        canRetry: true,
        errorObj: { ...actualError, message: actualError.error },
      };
    }
    return defaultRes;
  }
  return defaultRes;
};


Review comment (suggestion):
It got a bit more complicated. You return `errorObj` and it's only used when `canRetry` is true, but you're returning it in all paths here. I'd move `isRetry` outside of this function because it's not anywhere except fro early return. 

What about something like this?

```js
const makeMigrationCall(...) => {
 // ...


  const onError = err => {
      if (!isRetry) {
        const dependecyError = getRetryStatus(isRetry, err);
        if (dependecyError) return retryMigration(dependecyError, errorMsg);
      }  

     dispatch(handleMigrationErrors(errorMsg, err));
     customOnError(err);
  }
}

export const getDependencyError = (isRetry, err = {}) => {
  if (err.code == ERROR_CODES.dependencyError.code) return err;
  
  if (err.code == ERROR_CODES.dataApiError.code) {
      const actualError = isJsonString(err.message) ? JSON.parse(err.message) : {};
      if (actualError.code == ERROR_CODES.dependencyError.code) return { ...actualError, message: actualError.error }
  }
  return null;
}
```

Code after:
FROM
  pg_class
WHERE
  oid = (quote_ident('${schemaName}') || '.' || quote_ident('${tableName}'))::regclass::oid
  AND relname = '${tableName}';
`;
};

export const isColTypeString = colType =>
  ['text', 'varchar', 'char', 'bpchar', 'name'].includes(colType);

export const cascadeUpQueries = (upQueries = []) =>
  upQueries.map((i = {}) => {
    if (i.type === 'run_sql' || i.type === 'untrack_table') {
      return {
        ...i,
        args: {
          ...i.args,
          cascade: true,
        },
      };
    }
    return i;
  });

export const getDependencyError = (err = {}) => {
  if (err.code == ERROR_CODES.dependencyError.code) {
    // direct dependency error
    return err;
  } else if (err.code == ERROR_CODES.dataApiError.code) {
    // message is coming as error, further parssing willbe based on message key
    const actualError = isJsonString(err.message)
      ? JSON.parse(err.message)
      : {};
    if (actualError.code == ERROR_CODES.dependencyError.code) {
      return { ...actualError, message: actualError.error };
    }
  }
};