Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

150
Views
PushManger.subscribe devuelve un resultado NULL

Usamos notificaciones automáticas en el sitio. El código de trabajo es bastante sencillo.

 const subscribe = async () => { let sub = await self.registration.pushManager.getSubscription(); if(!sub) { sub = await self.registration.pushManager.subscribe({ applicationServerKey: serverKey(), userVisibleOnly: true }); } let resp; try { resp = await fetch('/subscribe', { method: 'post', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(sub) }); const body = await resp.json(); if(body.status !== 'ok') resp = null; } catch(e) { resp = null; } if(resp) return; if(sub.unsubscribe) { sub.unsubscribe(); } else { self.registration.pushManager.unregister(sub.endpoint); } await self.registration.unregister(); };

Babel procesa el código anterior antes de aterrizar en la producción de la causa. Funciona bastante bien para nosotros y para la mayoría de nuestros usuarios.

Pero de vez en cuando recibimos informes de error del back-end que dicen que los datos de suscripción recién recibidos son 'nulos'. Quiero decir literalmente: el punto final '/subscribe' obtiene una cadena 'nula' en lugar de un objeto de suscripción codificado en JSON.

¿Es posible que pushManager.subscribe devuelva NULL en lugar del objeto de suscripción?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!