[MM-38433] Error checking when a bad server URL is entered (#1728)
* [MM-38433] Error checking when a bad server URL is entered * Add proper error handler call
This commit is contained in:
@@ -37,8 +37,14 @@ export async function getServerAPI<T>(url: URL, isAuthenticated: boolean, onSucc
|
|||||||
if (response.statusCode === 200) {
|
if (response.statusCode === 200) {
|
||||||
response.on('data', (chunk: Buffer) => {
|
response.on('data', (chunk: Buffer) => {
|
||||||
const raw = `${chunk}`;
|
const raw = `${chunk}`;
|
||||||
const data = JSON.parse(raw) as T;
|
try {
|
||||||
onSuccess(data);
|
const data = JSON.parse(raw) as T;
|
||||||
|
onSuccess(data);
|
||||||
|
} catch (e) {
|
||||||
|
const error = `Error parsing server data from ${url.toString()}`;
|
||||||
|
log.error(error);
|
||||||
|
onError?.(new Error(error));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
onError?.(new Error(`Bad status code requesting from ${url.toString()}`));
|
onError?.(new Error(`Bad status code requesting from ${url.toString()}`));
|
||||||
|
Reference in New Issue
Block a user