nextemos 3.2.0 → 3.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -46,6 +46,10 @@ const fetchRequest = () => {
|
|
|
46
46
|
logger_1.default.info(`Fetch Request: ${method} - ${apiURL} - ${JSON.stringify(Object.assign({ cache: 'no-cache' }, options))}`);
|
|
47
47
|
try {
|
|
48
48
|
const response = yield fetch(apiURL.toString(), Object.assign(Object.assign({ cache: 'no-cache' }, options), { method }));
|
|
49
|
+
if (!response.ok) {
|
|
50
|
+
const errorDetail = yield response.text();
|
|
51
|
+
throw new Error(`Fetch Request HTTP Error: ${response.status} - ${errorDetail}`);
|
|
52
|
+
}
|
|
49
53
|
// Headers nesnesini Object'e dönüştürme
|
|
50
54
|
const headers = {};
|
|
51
55
|
if (response === null || response === void 0 ? void 0 : response.headers) {
|
|
@@ -55,19 +59,25 @@ const fetchRequest = () => {
|
|
|
55
59
|
}
|
|
56
60
|
// response data nesnesini JSON'a dönüştürme.
|
|
57
61
|
const responseData = yield response.json().catch(() => ({}));
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
return { status: response.status, data: responseData, headers };
|
|
62
|
+
return {
|
|
63
|
+
status: response.status,
|
|
64
|
+
data: responseData,
|
|
65
|
+
headers
|
|
66
|
+
};
|
|
65
67
|
}
|
|
66
68
|
catch (error) {
|
|
67
|
-
logger_1.default.fatal(`Fetch Request Exception Error! -> ${error}`);
|
|
69
|
+
logger_1.default.fatal(`Fetch Request Exception Error! -> ${apiURL}: ${error}`);
|
|
70
|
+
if (error instanceof Error) {
|
|
71
|
+
return {
|
|
72
|
+
status: 500,
|
|
73
|
+
error: error.name,
|
|
74
|
+
errorMessage: error.message
|
|
75
|
+
};
|
|
76
|
+
}
|
|
68
77
|
return {
|
|
69
78
|
status: 500,
|
|
70
|
-
error: `${error}
|
|
79
|
+
error: `${error}`,
|
|
80
|
+
errorMessage: `${error}`
|
|
71
81
|
};
|
|
72
82
|
}
|
|
73
83
|
});
|
|
@@ -45,8 +45,15 @@ export interface IApiResponse<T = any> {
|
|
|
45
45
|
/**
|
|
46
46
|
* API çağrısı sırasında meydana gelen hata mesajı.
|
|
47
47
|
* Bu alan opsiyoneldir ve API çağrısı başarısız olduğunda kullanılır.
|
|
48
|
+
* Hata mesajının adını içerir
|
|
48
49
|
*/
|
|
49
50
|
error?: string;
|
|
51
|
+
/**
|
|
52
|
+
* API çağrısı sırasında meydana gelen hata mesajı.
|
|
53
|
+
* Bu alan opsiyoneldir ve API çağrısı başarısız olduğunda kullanılır.
|
|
54
|
+
* Hata mesajına dair detayları içerir
|
|
55
|
+
*/
|
|
56
|
+
errorMessage?: string;
|
|
50
57
|
/**
|
|
51
58
|
* HTTP durum kodu.
|
|
52
59
|
* Bu alan, API çağrısının HTTP durum kodunu belirtir (ör. 200, 404, 500).
|