Unify Harbor error handling across server and client
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import http from 'node:http';
|
||||
import { HarborError } from '../shared/errors.js';
|
||||
|
||||
function request(socketPath, pathname, method = 'GET') {
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -27,8 +28,15 @@ function request(socketPath, pathname, method = 'GET') {
|
||||
export function createDataplaneClient(socketPath, send = request) {
|
||||
let current = { running: false, startedAt: null };
|
||||
const update = async (pathname, method) => {
|
||||
current = await send(socketPath, pathname, method);
|
||||
return current;
|
||||
try {
|
||||
current = await send(socketPath, pathname, method);
|
||||
return current;
|
||||
} catch (cause) {
|
||||
if (pathname === '/apply' || pathname === '/restart') {
|
||||
throw new HarborError('PROCESS_START_FAILED', { cause });
|
||||
}
|
||||
throw cause;
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user