Skip to content

Commit

Permalink
feat: allow accessing raw response from error
Browse files Browse the repository at this point in the history
  • Loading branch information
ayZagen committed Apr 20, 2024
1 parent a184d7f commit dfef284
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
10 changes: 8 additions & 2 deletions src/ui/utils/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ export function createFetchWrapper(baseUrl?: string) {
if (contentType && contentType.includes('json')) {
response = JSON.parse(value)
} else {
response = value
// noinspection JSPrimitiveTypeWrapperUsage
response = new String(value)
}
if (rawResponse.ok) {
resolve(response)
Expand All @@ -69,7 +70,12 @@ export function createFetchWrapper(baseUrl?: string) {
window.location.replace(response.location);
return false;
} else {
reject(response ? response : rawResponse.statusText)
// noinspection JSPrimitiveTypeWrapperUsage
const errorResponse = response || new String(rawResponse.statusText)
Object.defineProperty(errorResponse, '$raw', {
value: rawResponse
})
reject(errorResponse)
}
})
}).catch(reject)
Expand Down
8 changes: 8 additions & 0 deletions src/ui/utils/form_generics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ export function useGenericForm(
path: `errors.${e.error}`,
args: e,
}
} else if(e.error === 'too_many_requests' && e.$raw?.headers?.get){
const retryAfter = e.$raw.headers.get('retry-after')
form.value.toggleAlert({
path: `errors.${e.error}`,
args: {
retry: retryAfter
}
})
} else {
form.value.toggleAlert({
path: `errors.${e.error}`,
Expand Down
9 changes: 0 additions & 9 deletions src/ui/views/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,6 @@ export default defineComponent({
finalFields.password.errors = `errors.${e.error}`;
}
break;
case 'too_many_requests':
const retryAfter = e._raw.headers.get('retry-after')
form.value.toggleAlert({
path: `errors.${e.error}`,
args: {
retry: retryAfter
}
})
break;
default:
throw e
}
Expand Down

0 comments on commit dfef284

Please sign in to comment.