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

Errors page single with localization (js version) #88

Open
MdreW opened this issue Nov 10, 2023 · 3 comments
Open

Errors page single with localization (js version) #88

MdreW opened this issue Nov 10, 2023 · 3 comments

Comments

@MdreW
Copy link
Collaborator

MdreW commented Nov 10, 2023

New proposal for errors page.

Use the same errors page for all errors and add more detail and localization with javascript.

For security reason the errors details can't be add from with a simple string, but must be decoded from the error's code.

With a javascript we read a json with all codes and his error details and add this in the error box.

Vantage:

  • we an remove jinja from requisites
  • We can load the errors messages and other details from simple a json file
  • Is simple presonalize the template and the messages
  • don't require an asyncronous page generation (like Static page errors #82)

example json:

en:
  '20':  ''Destination is not valid'
  '30': 'Issuer NameFormat is invalid'
it:
  '20': 'Destinazione di ritorno non valida'
  '30': 'issuer non valido'
@MdreW
Copy link
Collaborator Author

MdreW commented Dec 4, 2023

@peppelinux , I have written a simple demo for a errors page single with localization, is a really simple js.
In this example I have added a single error (code 100) and I have added the ID 'error' at the page box.

errors.js

const localizations = {
  'it': {
    '100': 'Autenticazione fallita'
  },
  'en': {
    '100': 'Authentication fail'
  }
}

document.addEventListener("DOMContentLoaded", () => {
  let default_locale = 'it'
  let available_locales = ['it','en']
  let params = new URLSearchParams(window.location.search)
  let locale = available_locales.includes(params.get('locale')) ? params.get('locale') :  default_locale ;
  let element = document.getElementById('error') 
  if (localizations[locale][params.get('error')]) { 
    element.innerHTML = localizations[locale][params.get('error')] 
  }
});

Without options return the standard error page /static/error_page.html
image

If I add the error option in the url and the error is present in the localization the page will be updated /static/error_page.html?error=100
image

Optionally I ca add also the locale option /static/error_page.html?locale=en&error=100
image

We can also detach the localization from the error.js, in a single locale json or with different json file for each locale.
At this moment we have 24 different errors messages (SPID), I not know the wallet error prerequisite.
Write more different files is cute but not mandatory.

What do you think about it?

@peppelinux
Copy link
Member

@MdreW very interesting feature

I'd like to have it in 2.1.0 together with i18n in pyeudiw

if you can go ahead with a PR we'll get it in time, we won't change the templates in this version 2.0.0

@MdreW
Copy link
Collaborator Author

MdreW commented Feb 8, 2024

Ok, I will work for this 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants