Episodes
KelseyDH said over 2 years ago on API Structure and Error Handling :
I use the same pattern but skip the concern in `application_controller`, because I've never found concerns useful unless you have exactly repeating code needed in many places. Concerns are concerning!

David Kimura PRO said over 2 years ago on API Structure and Error Handling :
I agree with the concerns. It's really helpful in repeatability situations. However, it does work in single use cases as well. It could have just as easily been moved to the lib folder or something else. The main point wasn't where to put it, but rather don't clutter up the `application_controller`.

mcfoton PRO said over 2 years ago on API Structure and Error Handling :
Thanks for the episode! Enjoing it as always. So you've shown how to use built-in rails validations and errors structure to generate error messages for the API. How would you then suggest to handle more complex cases when you may have errors that are not connected 1 to 1 with a field on the model? For example, if the user builds a Cart on the mobile app by adding Items to it and many things can produce an error when the user clicks 'Checkout': invalid coupon, some of the items out of stock, some with reduced quantity... I believe a separate service class is the way to go (CartHandler of sorts) that would make all this checks, but how would you suggest to transalte all this different errors to the client app? Any thoughts from your experience would be very welcome :)

David Kimura PRO said over 2 years ago on API Structure and Error Handling :
I would try to keep it as simple as possible. In some cases where you are trying to validate a coupon code, you may want to raise a custom error for the coupon code if it is not valid. Add a catch for that error within the RescueHandler and respond back with the appropriate message. On some cases where you may have nested_attributes_for, you should have validations within the nested attributes and those should be taken into consideration when creating and updating records. For example, if I have a `book` which has many `authors` and the authors are created via `accepts_nested_attributes_for`, when I make a post to the books with the parameters `book[authors_attributes][0][full_name] = ""`, I would get the response `{"message":"Validation failed: Authors full name can't be blank"}`

marvinick said over 2 years ago on API Structure and Error Handling :
The video won't play. Along with other videos as well. Error message "The media cannot be loaded . . . ." appears after a few seconds. I also tried to get slack invite, I have not received any invitation in my email.

David Kimura PRO said over 2 years ago on API Structure and Error Handling :
thanks for letting me know. what browser and version are you using

marvinick said over 2 years ago on API Structure and Error Handling :
Chrome 80 macOS 10.15 Thanks for the quick reply. It seems to work now though. I'm not sure what happened last night and this morning.

David Kimura PRO said over 2 years ago on API Structure and Error Handling :
I've been testing something out and think that I've worked out the kinks with it. Check https://www.driftingruby.com/episodes/pow to see if you're able to play this one. If you're able to, then all is good.

marvinick said over 2 years ago on API Structure and Error Handling :
Hmm that's weird. https://www.driftingruby.com/episodes/pow is not working for me. Infinite loading. The other videos though are fine.

David Kimura PRO said over 2 years ago on API Structure and Error Handling :
That's really strange. Any JS errors in the console? I wonder if any browser extensions could be blocking those videos.

marvinick said over 2 years ago on API Structure and Error Handling :
I get *Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('https://js.stripe.com') does not match the recipient window's origin ('https://www.driftingruby.com').* in the console, when I navigate to https://www.driftingruby.com/episodes/pow Again, the other videos are now working as expected.

David Kimura PRO said over 2 years ago on API Structure and Error Handling :
That wouldn't affect video playback. I wonder what it shows once you try playing the video and what shows up on the network tab. I'm on macOS 10.15 as well with Chrome 80 and haven't experienced this. I wonder if there is some other kind of networking issue at play here.

Jeffrey Soong said about 2 years ago on API Structure and Error Handling :
Really awesome way to refactor the json_render. I've always felt something can be done there, but I could never quite place my finger on it. The consistency part really resonates, and for error responses, I return @resource.errors.full_messages so that I get an array of strings in human readable sentence.

Login to Comment