Skip to content

Improve error handling for token auth #54

@luisjunco

Description

@luisjunco

Issue

For token based auth, when a token is not valid or not provided, the api returns a 500 error.

Sending a 401 would be more appropriate plus, can help students to identify easier why their requests failed.

image

Solution

In error-handling\index.js, we can improve error handling adding the following:

//Unauthorized
if (err.name === "UnauthorizedError") {
  res.status(401).json({ message: `Unauthorized: ${err.inner?.message}` });
}

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions