-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Adding human readable 403 error access restricted (#1569)
Updated to have human-readable forbidden error (403)
- Loading branch information
1 parent
811be22
commit e6bce56
Showing
8 changed files
with
173 additions
and
64 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { API_ERROR_TYPES } from '../constants'; | ||
|
||
export const getErrorDetails = (error, dismissible = true) => { | ||
const errorInfo = { dismissible }; | ||
if (error.response?.status === 403) { | ||
// For 403 status the error shouldn't be dismissible | ||
errorInfo.dismissible = false; | ||
errorInfo.type = API_ERROR_TYPES.forbidden; | ||
errorInfo.status = error.response.status; | ||
} else if (error.response?.data) { | ||
const { data } = error.response; | ||
if ((typeof data === 'string' && !data.includes('</html>')) || typeof data === 'object') { | ||
errorInfo.data = JSON.stringify(data); | ||
} | ||
errorInfo.status = error.response.status; | ||
errorInfo.type = API_ERROR_TYPES.serverError; | ||
} else if (error.request) { | ||
errorInfo.type = API_ERROR_TYPES.networkError; | ||
} else { | ||
errorInfo.type = API_ERROR_TYPES.unknown; | ||
errorInfo.data = error.message; | ||
} | ||
return errorInfo; | ||
}; |
Oops, something went wrong.