Ready to get started?

Join Adocasts Plus for $8/mo, or sign into an existing Adocasts Plus account, to get access to all of our lessons.

robot mascot smiling

API Authorization Checks

In This Lesson

We'll implement our API Authorization checks across all the API controller methods we've implemented thus far. We'll then create a specific access token for each operation (read, create, update, and delete) to ensure everything is working.

Created by
@tomgobich
Published

Join the Discussion 2 comments

Create a free account to join in on the discussion
  1. @aaron-ford

    Can we clean up the error responses and not have it return the frames array? Just message, name, status?

    1
    1. Responding to aaron-ford
      @tomgobich

      Ah - it didn't occur to me, but I should've noted this in the lesson. Similar to the HTML Youch page, the frames here is only included in when debugging. It should be omitted when your application is running on production. I believe only message is included in production.

      If you do wish to customize the exception, though, you can do that within the exception's handle method. This can be done globally within the handle.ts method or any individual custom exceptions. You can also narrow in on a specific exception within handle.ts as well:

      /**
      * The method is used for handling errors and returning
      * response to the client
      */
      async handle(error: unknown, ctx: HttpContext) {
        if (error instanceof errors.E_HTTP_EXCEPTION) {
          return ctx.response.status(error.status).send({ message: 'Oh no!' })
        }
      
        return super.handle(error, ctx)
      }
      Copied!
      0