Explorar el Código

[editor] Switch to axios for the format SQL ajax request

Johan Ahlen hace 5 años
padre
commit
39ebbf87e6
Se han modificado 1 ficheros con 15 adiciones y 13 borrados
  1. 15 13
      desktop/core/src/desktop/js/apps/notebook2/apiUtils.ts

+ 15 - 13
desktop/core/src/desktop/js/apps/notebook2/apiUtils.ts

@@ -14,25 +14,27 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-import { simplePost } from 'api/apiUtilsV2';
-import { FORMAT_SQL_API } from 'api/urls';
+import axios from 'axios';
+
+type FormatSqlApiResponse = {
+  formatted_statements?: string;
+  status: number;
+};
+
+const FORMAT_SQL_API_URL = '/notebook/api/format';
 
 export const formatSql = async (options: {
   statements: string;
   silenceErrors?: boolean;
 }): Promise<string> => {
   try {
-    const response = await simplePost<
-      {
-        formatted_statements: string;
-        status: number;
-      },
-      { statements: string }
-    >(FORMAT_SQL_API, options, {
-      silenceErrors: !!options.silenceErrors,
-      ignoreSuccessErrors: true
-    });
-    return (response && response.formatted_statements) || options.statements;
+    const params = new URLSearchParams();
+    params.append('statements', options.statements);
+    const response = await axios.post<FormatSqlApiResponse>(FORMAT_SQL_API_URL, params);
+
+    if (response.data.status !== -1 && response.data.formatted_statements) {
+      return response.data.formatted_statements;
+    }
   } catch (err) {
     if (!options.silenceErrors) {
       throw err;