Skip to content

Commit a45a76a

Browse files
Better logging for CORS errors
1 parent b174bcb commit a45a76a

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/api.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ export function fetchAuthenticationInfo(authUrl: string): Promise<Authentication
4848
}
4949
} else if (status === 401) {
5050
resolve(null)
51+
} else if (status === 0) {
52+
logCorsError()
53+
reject({
54+
status: 503,
55+
message: "Unable to process authentication response",
56+
})
5157
} else {
5258
reject({
5359
status,
@@ -79,6 +85,12 @@ export function logout(authUrl: string): Promise<LogoutResponse> {
7985
if (status >= 200 && status < 300) {
8086
const jsonResponse = JSON.parse(http.responseText)
8187
resolve(jsonResponse)
88+
} else if (status === 0) {
89+
logCorsError()
90+
reject({
91+
status: 503,
92+
message: "Unable to process authentication response",
93+
})
8294
} else {
8395
console.error("Logout error", http.status, http.responseText)
8496
reject({
@@ -138,3 +150,11 @@ export function parseJsonConvertingSnakeToCamel(str: string): AuthenticationInfo
138150
function toUserRole(userRole: string): UserRole {
139151
return UserRole[userRole as keyof typeof UserRole]
140152
}
153+
154+
function logCorsError() {
155+
console.error(
156+
"Request to PropelAuth failed due to a CORS error. There are a few likely causes: \n" +
157+
" 1. In the Frontend Integration section of your dashboard, make sure your requests are coming either the specified Application URL or localhost with a matching port.\n" +
158+
" 2. Make sure your server is hosted on HTTPS in production."
159+
)
160+
}

0 commit comments

Comments
 (0)