Skip to main content
View on YouTube to comment and like!

Syntax Video

FREE DEV STICKERS! | Fixing a bug with Sentry

Chapter 1 00:00

Transcript

what's up CJ here we're panicking so we just launched uh free stickers for anybody that signs up for our newsletter here at syntax but the website is broken and everyone is complaining so if you go to syntax. fm/ snackpack it just says Oopsy Daisy and the page doesn't actually load so we're going to use Sentry to fix this uh because people need their free stickers so I opened up the Sentry dashboard and you can see all of these issues coming in and I'm going to try to narrow it down so I'm running the code locally and the issue happens when someone goes directly to syntax.

fm/ snackpack so when they go there it says Oopsy Daisy but when I run this locally I can't even replicate it so this is a perfect use case for a century because it literally shows the the trace of what's happening in production so we're getting all these errors here and I think it has something to do with reaching out to convert kit so convert kit is where we store our newsletters and so yeah I guess locally because I don't have an apepi key it's not running but let's look at this first issue here and we can see that yeah it can't do a json. parse I think if I want to replicate this locally I'm going to need a convert kit API key so that way the past issues actually load sweet okay so I got the API key installed locally and now I can replicate it locally so that's great yeah and this unexpected token R is definitely happening from a Json parse so we can see in the Sentry log here that's happening happening in Fetch

broadcast list so this is in routes site snackpack page. server routes sight snackpack page. server and then fetch broadcast list and right here we're trying to parse this as Json so let's just do some intermediary logging on both of these right here I'm just going to log out the response and see what's going on yeah so it's a 200 okay and yeah it literally just says retry later oh okay I'm wondering if there's any headers we can look at that says like rate limited or something like that headers nothing useful here the body just says retry later okay so I think what we'll do is try catch json.parse if that fails just give back an empty array and that way the list of past issues will just be an empty array and then that should at least get the page from completely crashing for now okay uh we need to do this for both pages so I'm just going to extract this out into a little re usable function we'll call it

like parse response that looks good okay Moment of Truth the page loads and there are no past issues this is definitely some code we want in there because if it can just reply with something that's not valid Json we need to be able to handle that now I think we're making other calls to their API let's see there's that one there's this one I we should probably you know do do a little parse thingy here to make sure it doesn't respond with retry later we're going to try catch this load all of this in there and then if that fails we're just going to return an empty array okay so that's looking good that should help us if in the future that endpoint starts to fail so I think the last thing we'll do is on the front end if issue length is zero we'll just say uhoh error loading issues so in the codes page. spelt should have it I'm just going to have an if statement here so if it doesn't have a link then we're going to show an error message oop see Daisy to load past issues and now when I'm running here

unable to load past issues okay this is the fix for now I could look at the convert kit docs but I just want to get this working so we're going to push this to prod hopefully that fixes it for all the users and then we can potentially look into why some of these other errors are happening but for now Sentry saved the day so if you are not using cry in production this is the way to go we would not have known that this was an issue or even how to debug it because you saw initially when I was running locally I didn't even see it so the fact that we can actually see the errors that the users are getting uh in production is huge and it basically led me exactly to the spot where I needed to debug and fix this so I'm going to get this merged in pushed up I'll create a PR for Scott to review and if you're not you should subscribe to the newsletter so syntax.

fm/ snackpack the page should actually load now if you sign up for the newsletter you'll get this free sticker pack it has all these cool stickers and the back of it is this cool little postcard that you can like put on your fridge or something like that so sign up for the snack pack sign up for Sentry Sentry .io syntax and you can use code tasty treat you'll get two months free like I said if you're not using centry and production you're Flying Blind so definitely use centry definitely go sign up for the snackpack see you later

Quote it with credit and a link. Quoting Syntax