Skip to content

Commit

Permalink
kao-logic: Re-structure xhr logic
Browse files Browse the repository at this point in the history
- Re-structure how XHR logic work for catch error, since BE already updated to fix several issue
that causing internal server error (500). Then FE on XHR service need to re-structure to simplify
and only catch what required message to show to users as end message
- Bump FE Module into 3.2.8

Signed-off-by: Dicky Herlambang (花) <herlambangdicky5@gmail.com>
  • Loading branch information
Nicklas373 committed Jul 7, 2024
1 parent 10a8b79 commit 2b47b53
Showing 1 changed file with 11 additions and 42 deletions.
53 changes: 11 additions & 42 deletions resources/js/kao-logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const options = {
const adobeClientID = "STATIC_CLIENT_ID"
const appMajorVer = 3
const appMinorVer = 2
const appPatchVer = 7
const appPatchVer = 8
const apiUrl = 'http://192.168.0.2'
const bearerToken = "STATIC_BEARER"
const commitHash = gitHash
Expand Down Expand Up @@ -202,7 +202,6 @@ if (whatsNewBtn) {
errListTitleMessage.innerText = "Error message"
resetErrListMessage()
generateMesssage(error.versionFetchMessage)
generateMesssage("Unable to fetch latest changelog")
errAltSubMessageModal.style = null
loadingModal.hide()
errModal.show()
Expand Down Expand Up @@ -1070,8 +1069,8 @@ function fetchVersion() {
if (xhr.readyState == 4) {
clearInterval(timerStart)
if (xhr.responseText.trim().startsWith('{')) {
var xhrReturn = JSON.parse(xhr.responseText)
if (xhr.status == 200) {
var xhrReturn = JSON.parse(xhr.responseText)
if (xhrReturn.errors == null) {
resolve({
versionFetchCheck: true,
Expand All @@ -1089,37 +1088,21 @@ function fetchVersion() {
versionFetchError: xhrReturn.errors
})
}
} else if (xhr.status == 429) {
reject({
versionFetchCheck: false,
versionFetchStats: 429,
versionFetchMessage: xhrReturn.message,
versionFetchResponse: xhrReturn.response,
versionFetchError: 'Too many request'
})
} else if (xhr.status == 524) {
reject({
versionFetchCheck: false,
versionFetchStats: 524,
versionFetchMessage: xhrReturn.message,
versionFetchResponse: xhrReturn.response,
versionFetchError: 'Connection Timeout'
})
} else {
reject({
versionFetchCheck: false,
versionFetchStats: xhrReturn.status,
versionFetchMessage: xhrReturn.message,
versionFetchResponse: xhrReturn.response,
versionFetchError: 'Internal Server Error'
versionFetchError: xhrReturn.errors
})
}
} else {
reject({
versionFetchCheck: false,
versionFetchStats: 0,
versionFetchMessage: 'Internal server error (0)',
versionFetchResponse: xhrReturn.response,
versionFetchStats: xhr.status,
versionFetchMessage: xhr.message,
versionFetchResponse: 'Internal Server Error',
versionFetchError: 'Internal Server Error'
})
}
Expand Down Expand Up @@ -2436,8 +2419,8 @@ function validateVersion() {
if (xhr.readyState == 4) {
clearInterval(timerStart)
if (xhr.responseText.trim().startsWith('{')) {
var xhrReturn = JSON.parse(xhr.responseText)
if (xhr.status == 200) {
var xhrReturn = JSON.parse(xhr.responseText)
if (xhrReturn.errors == null) {
resolve({
versioningCheck: true,
Expand All @@ -2453,38 +2436,24 @@ function validateVersion() {
versioningError: xhrReturn.errors
})
}
} else if (xhr.status == 429) {
reject({
versioningCheck: false,
versioningStats: 429,
versioningMessage: xhrReturn.message,
versioningError: 'Too many request'
})
} else if (xhr.status == 524) {
reject({
versioningCheck: false,
versioningStats: 524,
versioningMessage: xhrReturn.message,
versioningError: 'Connection Timeout'
})
} else {
reject({
versioningCheck: false,
versioningStats: xhrReturn.status,
versioningMessage: xhrReturn.message,
versioningError: 'Internal Server Error'
versioningError: xhrReturn.errors
})
}
} else {
reject({
versioningCheck: false,
versioningStats: 0,
versioningMessage: 'Internal server error (0)',
versioningStats: xhr.status,
versioningMessage: xhr.message,
versioningError: 'Internal Server Error'
})
}
}
}
xhr.send(formData)
})
}
}

0 comments on commit 2b47b53

Please sign in to comment.