Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Bugfix 404 response from getFlowError #193

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
11 changes: 10 additions & 1 deletion examples/nextjs-spa/src/pages/error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,16 @@ const Error: NextPageWithLayout = () => {
.then(({ data }) => {
setError(JSON.stringify(data, null, 2))
})
.catch(handleError)
.catch((error: AxiosError) => {
switch (error.response?.status) {
case 404: {
// The kratos handler for /self-service/errors?id=some_error_id currently only handles id=stub:500, and will 404 for everything else
// See https://github.com/ory/kratos/blob/4fb28b363622bb21ce12d9f89d2ceb4649aa0cba/selfservice/errorx/handler.go#L106
return;
}
}
handleError(error).then();
});
}
}, [err, id, router.isReady, handleError])

Expand Down
12 changes: 12 additions & 0 deletions examples/nextjs-spa/src/pkg/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ export const HandleError = (
return Promise.resolve()
}

const configData = error.config?.data;
if (error.config && configData && (typeof configData === "string" || configData instanceof String)) {
// Sanitise any payloads where the top level key is "password" so they don't end up in the URLs
try {
const parsedData = JSON.parse(configData.toString());
if (parsedData.password) {
parsedData.password = "REDACTED";
}
error.config.data = JSON.stringify(parsedData);
} catch (e) {}
}

const responseData = error.response?.data || {}

switch (error.response?.status) {
Expand Down
Loading