-
Notifications
You must be signed in to change notification settings - Fork 119
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
Introduce Error 404 page #1107
Introduce Error 404 page #1107
Conversation
Quetzacoalt91
commented
Jan 8, 2025
Questions | Answers |
---|---|
Description? | Implement the display of the page "Page Not Found" |
Type? | new feature |
BC breaks? | Nope |
Deprecations? | Nope |
Fixed ticket? | / |
Sponsor company | @PrestaShopCorp |
How to test? | When you attempt to load a non-existing page, the page 404 is displayed. |
5241a8f
to
84fd7db
Compare
6861be5
to
9b3a46c
Compare
// A couple or errors are returned in an actual response (i.e 404 or 500) | ||
if (error instanceof AxiosError) { | ||
if (error.response?.data) { | ||
const responseData = error.response.data; | ||
responseData.new_route = 'error-page'; | ||
await this.#handleResponse(responseData, true); | ||
} | ||
} else { | ||
// TODO: catch errors | ||
console.error(error); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Axios allows the use of interceptor, which allows specific behavior based on an error code. This would allow us to easily control/orient the view used and potentially have logic on a specific error.
Ex:
axiosInstance.interceptors.response.use(undefined, (error) => {
const { response } = error;
if (!response) {
history.push(ERROR_UNKNOWN);
} else {
const { status } = response;
switch (status) {
case 409:
break;
case 404:
history.push(ERROR_NOT_FOUND);
break;
case 401:
history.push(ERROR_UNAUTHORIZED);
break;
case 403:
history.push(ERROR_FORBIDDEN);
break;
case 500:
case 503:
case 400:
default:
history.push(ERROR_UNKNOWN);
}
}
return Promise.reject(error);
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea of using the interceptor, especially to validate the response contents from the back end.
I suggest to handle this in another pull-request though, as we only cover the HTTP 404 here.
public function getShopAdminAbsolutePathFromRequest(Request $request): string | ||
{ | ||
return rtrim($this->getShopAbsolutePathFromRequest($request), '/') . '/' . $this->adminFolder; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be worth it to also have one getViewsAbsolutePathFromRequest ?
public function getShopAdminAbsolutePathFromRequest(Request $request): string
{
returnrtrim($this->getShopAbsolutePathFromRequest($request), '/') . '/modules/autoupgrade/views';
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left this responsibility to the class AssetsGenerator as it is its only job to concatenate this path to the production or the development base URL/Path.
|
||
class Error404Controller extends AbstractPageController | ||
{ | ||
const ERROR_CODE = 404; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could use the constants already available in symfony (Symfony\Component\HttpFoundation\Response::HTTP_NOT_FOUND
)
a07f1e4
to
f0ee685
Compare
047e40a
047e40a
to
e3b67ab
Compare
baf0f9d
to
3bf01b5
Compare
3bf01b5
to
4d7799a
Compare
Co-authored-by: Morgan Pichat <[email protected]>
4d7799a
to
be9a57d
Compare
Quality Gate passedIssues Measures |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your PR, I tested it and it seems to works as you can see :
recording.45.webm
Tested on :
8.0.4 and 8.2
Because the PR seems to works as expected, It's QA ✔️
Thank you
PR merged, well done! Message to @PrestaShop/committers: do not forget to milestone it before the merge. |