-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: seven <[email protected]>
- Loading branch information
Showing
6 changed files
with
135 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { CustomError } from './customError'; | ||
|
||
const catchHandler = (err: unknown) => { | ||
if (err instanceof CustomError) { | ||
throw new CustomError(err.status, err.details); | ||
} | ||
if (err instanceof Error) { | ||
throw new CustomError(500, err.message); | ||
} | ||
throw new CustomError(500, `unknown error, trace: ${JSON.stringify(err)}`); | ||
}; | ||
|
||
const buildURL = (host: string, port: number, path?: string, queryParameters?: string) => { | ||
let url = `${host}:${port}`; | ||
url += path ?? ''; | ||
url += queryParameters ? `?${queryParameters}` : ''; | ||
|
||
return url; | ||
}; | ||
|
||
export const loadHttpClient = (host: string, port: number) => ({ | ||
get: async (path?: string, queryParameters?: string) => { | ||
const url = buildURL(host, port, path, queryParameters); | ||
try { | ||
const result = await fetch(url, { | ||
method: 'GET', | ||
headers: { 'Content-Type': 'application/json' }, | ||
}); | ||
const data = await result.json(); | ||
if (!result.ok) new CustomError(result.status, data); | ||
|
||
return data; | ||
} catch (e) { | ||
throw catchHandler(e); | ||
} | ||
}, | ||
post: async (path: string, queryParameters?: string, payload?: unknown) => { | ||
const url = buildURL(host, port, path, queryParameters); | ||
try { | ||
const result = await fetch(url, { | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: payload ? JSON.stringify(payload) : undefined, | ||
}); | ||
const data = await result.json(); | ||
if (!result.ok) new CustomError(result.status, data); | ||
return data; | ||
} catch (e) { | ||
throw catchHandler(e); | ||
} | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 20 additions & 8 deletions
28
...views/connect/components/table-select.vue → ...onnect/components/collection-selector.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters