-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
58f0e19
commit b81f5f0
Showing
9 changed files
with
75 additions
and
27 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,34 @@ | ||
import { AxiosError } from "axios"; | ||
import { ApiError, ApiResponseAction } from "../types/apiTypes"; | ||
|
||
export const toApiError = (error: AxiosError): ApiError => ({ | ||
code: error.status, | ||
type: error.code, | ||
requestParams: error.request, | ||
additionalContents: formatResponseContents(error) | ||
}); | ||
|
||
export const toApiResponseAction = (error: AxiosError): ApiResponseAction => ({ | ||
kind: 'action', | ||
error: true, | ||
next: 'Error', | ||
stepDone: null, | ||
status: 'error', | ||
next_desc: 'Error', | ||
nextParams: { | ||
progressPercentage: 0 | ||
}, | ||
nextQuickInfo: [], | ||
apiError: toApiError(error) | ||
}); | ||
|
||
export const isHttpErrorCode = (code?: number): boolean => { | ||
return typeof code === 'number' && code >= 300 && code.toString().length === 3; | ||
} | ||
const formatResponseContents = (error: AxiosError): string|undefined => { | ||
return typeof error.response?.data === 'string' | ||
? error.response?.data | ||
: JSON.stringify(error.response?.data); | ||
}; | ||
|
||
|
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
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
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