Skip to content

Instantly share code, notes, and snippets.

View rjurado01's full-sized avatar

Rafael Jurado González rjurado01

  • NoSoloSoftware Network
  • Spain
View GitHub Profile
@gsusmonzon
gsusmonzon / custom-entity-not-found-exception-filter.md
Last active February 17, 2024 06:04
Make NestJs returns 404 when EntityNotFoundError exception is thrown

Make NestJs returns 404 when EntityNotFoundError exception is thrown

When using findOrFail() or findOneOrFail() from typeORM, a 500 error is returned if there is no entity (EntityNotFoundError).

To make it returns a 404, use an exception filter as described in https://docs.nestjs.com/exception-filters .

file /src/filters/entity-not-found-exception.filter.ts

@laserlemon
laserlemon / introduction.md
Last active February 12, 2021 10:04
Rendering form errors for non-database-backed changesets

Introduction

Disclaimer: I'm a one-day-old Elixir/Phoenix developer.

In Sonny's training yesterday, we used an Ecto.Changeset to handle user registration (a database-backed operation). This worked perfectly for rendering the intial form and re-rendering the form with validation errors.

This is because our Workshop.RegistrationController is calling Repo.Insert which sets the changeset's :action, whether or not the insertion succeeds. Then Phoenix.HTML's form_for function appropriately sets errors on the form so they can be rendered on the page.

The Problem

@jgwhite
jgwhite / Gemfile
Created November 9, 2012 16:05
Testing Static HTML with RSpec & Capybara
source :rubygems
gem 'capybara'
gem 'rack'
gem 'rspec'