Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[Hotfix] Avoid throwing when credential request comes #18

Merged
merged 1 commit into from
Aug 22, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions frontend/src/apis/Core/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export async function rawRequest<T = any>(

return fetch(entryPoint, fullOptions)
.then((response) => {
return _handleAPIResponse<T>(response, convert)
return _handleAPIResponse<T>(entryPoint, response, convert)
})
.catch((error) => {
if (error instanceof APIError) {
Expand Down Expand Up @@ -231,8 +231,8 @@ export async function rawMultiRequest<T = any>(
)
.then((responses) => {
return responses.map(
(response) => {
return _handleAPIResponse<T>(response, convert)
(response, i) => {
return _handleAPIResponse<T>(entryPoints[i], response, convert)
})
})
.catch((error) => { throw new APIError(error.message) })
Expand All @@ -246,6 +246,7 @@ function generateFormData(params) {
}

function _handleAPIResponse<T = any>(
entryPoint: string,
response: Response,
convert: (response) => T = (r) => r
): Promise<any> {
Expand All @@ -255,6 +256,18 @@ function _handleAPIResponse<T = any>(
}

// Throw API error exception
if (entryPoint.endsWith('/credential')) {
return new Promise((_, reject) => {
response.json()
.then((resultJSON) => {
reject(new APIError(
resultJSON.message,
APIErrorType.serverside,
response.status
))
})
})
}
response.json().then(
(resultJSON) => {
throw new APIError(
Expand Down