An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
fix: Error handling
Andras Bacsai8fc3760eef9b
diff --git a/src/lib/database/common.ts b/src/lib/database/common.tsindex 23b13ba54d..cbbc556243 100644--- a/src/lib/database/common.ts+++ b/src/lib/database/common.ts@@ -41,7 +41,7 @@ export function ErrorHandler(e) {e = new Error(e.toString());}let truncatedError = e;- if (e.message.includes('docker run')) {+ if (e.message?.includes('docker run')) {let truncatedArray = [];truncatedArray = truncatedError.message.split('-').filter((line) => {if (!line.startsWith('e ')) {@@ -50,7 +50,7 @@ export function ErrorHandler(e) {});truncatedError.message = truncatedArray.join('-');}- if (e.message.includes('git clone')) {+ if (e.message?.includes('git clone')) {truncatedError.message = 'git clone failed';}sentry.captureException(truncatedError);@@ -61,11 +61,11 @@ export function ErrorHandler(e) {error: truncatedError.error || truncatedError.message}};- if (truncatedError.name === 'NotFoundError') {+ if (truncatedError?.name === 'NotFoundError') {payload.status = 404;}if (truncatedError instanceof P.PrismaClientKnownRequestError) {- if (truncatedError.code === 'P2002') {+ if (truncatedError?.code === 'P2002') {payload.body.message = 'Already exists. Choose another name.';}}diff --git a/src/lib/haproxy/index.ts b/src/lib/haproxy/index.tsindex 56b7ce789a..48b492d634 100644--- a/src/lib/haproxy/index.ts+++ b/src/lib/haproxy/index.ts@@ -107,11 +107,7 @@ export async function forceSSLOffApplication({ domain }) {export async function forceSSLOnApplication({ domain }) {if (!dev) {const haproxy = await haproxyInstance();- try {- await checkHAProxy(haproxy);- } catch (error) {- return;- }+ await checkHAProxy(haproxy);const transactionId = await getNextTransactionId();try {@@ -162,11 +158,7 @@ export async function forceSSLOnApplication({ domain }) {export async function deleteProxy({ id }) {const haproxy = await haproxyInstance();- try {- await checkHAProxy(haproxy);- } catch (error) {- return;- }+ await checkHAProxy(haproxy);const transactionId = await getNextTransactionId();try {await haproxy.get(`v2/services/haproxy/configuration/backends/${id}`).json();@@ -198,11 +190,7 @@ export async function reloadHaproxy(engine) {}export async function configureProxyForApplication({ domain, imageId, applicationId, port }) {const haproxy = await haproxyInstance();- try {- await checkHAProxy(haproxy);- } catch (error) {- return;- }+ await checkHAProxy(haproxy);let serverConfigured = false;let backendAvailable: any = null;@@ -283,11 +271,7 @@ export async function configureProxyForApplication({ domain, imageId, applicatioexport async function configureCoolifyProxyOff(fqdn) {const domain = getDomain(fqdn);const haproxy = await haproxyInstance();- try {- await checkHAProxy(haproxy);- } catch (error) {- return;- }+ await checkHAProxy(haproxy);try {const transactionId = await getNextTransactionId();@@ -308,22 +292,21 @@ export async function configureCoolifyProxyOff(fqdn) {throw error?.response?.body || error;}}-export async function checkHAProxy(haproxy) {+export async function checkHAProxy(haproxy?: any) {if (!haproxy) haproxy = await haproxyInstance();try {await haproxy.get('v2/info');} catch (error) {- throw 'HAProxy is not running, but it should be!';+ throw {+ message:+ 'Coolify Proxy is not running, but it should be!<br><br>Start it in the "Destinations" menu.'+ };}}export async function configureCoolifyProxyOn(fqdn) {const domain = getDomain(fqdn);const haproxy = await haproxyInstance();- try {- await checkHAProxy(haproxy);- } catch (error) {- return;- }+ await checkHAProxy(haproxy);let serverConfigured = false;let backendAvailable: any = null;try {@@ -572,12 +555,7 @@ export async function configureSimpleServiceProxyOn({ id, domain, port }) {export async function configureSimpleServiceProxyOff({ domain }) {const haproxy = await haproxyInstance();- try {- await checkHAProxy(haproxy);- } catch (error) {- return;- }-+ await checkHAProxy(haproxy);try {await haproxy.get(`v2/services/haproxy/configuration/backends/${domain}`).json();const transactionId = await getNextTransactionId();@@ -596,12 +574,7 @@ export async function configureSimpleServiceProxyOff({ domain }) {export async function removeWwwRedirection(domain) {const haproxy = await haproxyInstance();- try {- await checkHAProxy(haproxy);- } catch (error) {- return;- }-+ await checkHAProxy();const rules: any = await haproxy.get(`v2/services/haproxy/configuration/http_request_rules`, {searchParams: {@@ -631,11 +604,7 @@ export async function removeWwwRedirection(domain) {}export async function setWwwRedirection(fqdn) {const haproxy = await haproxyInstance();- try {- await checkHAProxy(haproxy);- } catch (error) {- return;- }+ await checkHAProxy(haproxy);const transactionId = await getNextTransactionId();try {diff --git a/src/routes/services/[id]/__layout.svelte b/src/routes/services/[id]/__layout.svelteindex 0beb4df6c1..21012ad3e7 100644--- a/src/routes/services/[id]/__layout.svelte+++ b/src/routes/services/[id]/__layout.svelte@@ -110,23 +110,23 @@loading = false;}}- onMount(async () => {- if (- service.type &&- service.destinationDockerId &&- service.version &&- service.fqdn &&- !isRunning- ) {- try {- await post(`/services/${service.id}/${service.type}/stop.json`, {});- } catch ({ error }) {- return errorNotification(error);- } finally {- loading = false;- }- }- });+ // onMount(async () => {+ // if (+ // service.type &&+ // service.destinationDockerId &&+ // service.version &&+ // service.fqdn &&+ // !isRunning+ // ) {+ // try {+ // await post(`/services/${service.id}/${service.type}/stop.json`, {});+ // } catch ({ error }) {+ // return errorNotification(error);+ // } finally {+ // loading = false;+ // }+ // }+ // });</script><nav class="nav-side">diff --git a/src/routes/services/[id]/minio/start.json.ts b/src/routes/services/[id]/minio/start.json.tsindex 2a939b8019..c08c18e545 100644--- a/src/routes/services/[id]/minio/start.json.ts+++ b/src/routes/services/[id]/minio/start.json.ts@@ -5,6 +5,7 @@ import yaml from 'js-yaml';import type { RequestHandler } from '@sveltejs/kit';import { letsEncrypt } from '$lib/letsencrypt';import {+ checkHAProxy,configureSimpleServiceProxyOn,reloadHaproxy,setWwwRedirection,@@ -22,6 +23,7 @@ export const post: RequestHandler = async (event) => {const { id } = event.params;try {+ await checkHAProxy();const service = await db.getService({ id, teamId });const {type,diff --git a/src/routes/services/[id]/nocodb/start.json.ts b/src/routes/services/[id]/nocodb/start.json.tsindex 43022209e5..3ce559e45b 100644--- a/src/routes/services/[id]/nocodb/start.json.ts+++ b/src/routes/services/[id]/nocodb/start.json.ts@@ -4,7 +4,12 @@ import { promises as fs } from 'fs';import yaml from 'js-yaml';import type { RequestHandler } from '@sveltejs/kit';import { letsEncrypt } from '$lib/letsencrypt';-import { configureSimpleServiceProxyOn, reloadHaproxy, setWwwRedirection } from '$lib/haproxy';+import {+ checkHAProxy,+ configureSimpleServiceProxyOn,+ reloadHaproxy,+ setWwwRedirection+} from '$lib/haproxy';import { getDomain } from '$lib/components/common';import { ErrorHandler } from '$lib/database';@@ -15,6 +20,7 @@ export const post: RequestHandler = async (event) => {const { id } = event.params;try {+ await checkHAProxy();const service = await db.getService({ id, teamId });const { type, version, fqdn, destinationDockerId, destinationDocker } = service;@@ -58,7 +64,6 @@ export const post: RequestHandler = async (event) => {status: 200};} catch (error) {- console.log(error);return ErrorHandler(error);}} catch (error) {diff --git a/src/routes/services/[id]/plausibleanalytics/start.json.ts b/src/routes/services/[id]/plausibleanalytics/start.json.tsindex 2f1ce9fd04..96dbac3c2a 100644--- a/src/routes/services/[id]/plausibleanalytics/start.json.ts+++ b/src/routes/services/[id]/plausibleanalytics/start.json.ts@@ -4,7 +4,12 @@ import { promises as fs } from 'fs';import yaml from 'js-yaml';import type { RequestHandler } from '@sveltejs/kit';import { letsEncrypt } from '$lib/letsencrypt';-import { configureSimpleServiceProxyOn, reloadHaproxy, setWwwRedirection } from '$lib/haproxy';+import {+ checkHAProxy,+ configureSimpleServiceProxyOn,+ reloadHaproxy,+ setWwwRedirection+} from '$lib/haproxy';import { getDomain } from '$lib/components/common';import { ErrorHandler } from '$lib/database';@@ -15,6 +20,7 @@ export const post: RequestHandler = async (event) => {const { id } = event.params;try {+ await checkHAProxy();const service = await db.getService({ id, teamId });const {type,diff --git a/src/routes/services/[id]/vaultwarden/start.json.ts b/src/routes/services/[id]/vaultwarden/start.json.tsindex fac46dc1c1..ab05590a81 100644--- a/src/routes/services/[id]/vaultwarden/start.json.ts+++ b/src/routes/services/[id]/vaultwarden/start.json.ts@@ -4,7 +4,12 @@ import { promises as fs } from 'fs';import yaml from 'js-yaml';import type { RequestHandler } from '@sveltejs/kit';import { letsEncrypt } from '$lib/letsencrypt';-import { configureSimpleServiceProxyOn, reloadHaproxy, setWwwRedirection } from '$lib/haproxy';+import {+ checkHAProxy,+ configureSimpleServiceProxyOn,+ reloadHaproxy,+ setWwwRedirection+} from '$lib/haproxy';import { getDomain } from '$lib/components/common';import { getServiceImage, ErrorHandler } from '$lib/database';@@ -15,6 +20,7 @@ export const post: RequestHandler = async (event) => {const { id } = event.params;try {+ await checkHAProxy();const service = await db.getService({ id, teamId });const { type, version, fqdn, destinationDockerId, destinationDocker } = service;diff --git a/src/routes/services/[id]/vscodeserver/start.json.ts b/src/routes/services/[id]/vscodeserver/start.json.tsindex 4a5ea2c226..4709a823eb 100644--- a/src/routes/services/[id]/vscodeserver/start.json.ts+++ b/src/routes/services/[id]/vscodeserver/start.json.ts@@ -4,7 +4,12 @@ import { promises as fs } from 'fs';import yaml from 'js-yaml';import type { RequestHandler } from '@sveltejs/kit';import { letsEncrypt } from '$lib/letsencrypt';-import { configureSimpleServiceProxyOn, reloadHaproxy, setWwwRedirection } from '$lib/haproxy';+import {+ checkHAProxy,+ configureSimpleServiceProxyOn,+ reloadHaproxy,+ setWwwRedirection+} from '$lib/haproxy';import { getDomain } from '$lib/components/common';import { ErrorHandler } from '$lib/database';@@ -15,6 +20,7 @@ export const post: RequestHandler = async (event) => {const { id } = event.params;try {+ await checkHAProxy();const service = await db.getService({ id, teamId });const {type,diff --git a/src/routes/services/[id]/wordpress/start.json.ts b/src/routes/services/[id]/wordpress/start.json.tsindex 81fa1eda83..2ed3039cd9 100644--- a/src/routes/services/[id]/wordpress/start.json.ts+++ b/src/routes/services/[id]/wordpress/start.json.ts@@ -4,7 +4,12 @@ import { promises as fs } from 'fs';import yaml from 'js-yaml';import type { RequestHandler } from '@sveltejs/kit';import { letsEncrypt } from '$lib/letsencrypt';-import { configureSimpleServiceProxyOn, reloadHaproxy, setWwwRedirection } from '$lib/haproxy';+import {+ checkHAProxy,+ configureSimpleServiceProxyOn,+ reloadHaproxy,+ setWwwRedirection+} from '$lib/haproxy';import { getDomain } from '$lib/components/common';import { ErrorHandler } from '$lib/database';@@ -15,6 +20,7 @@ export const post: RequestHandler = async (event) => {const { id } = event.params;try {+ await checkHAProxy();const service = await db.getService({ id, teamId });const {type,