elysiajs / elysia

Ergonomic Framework for Humans
https://elysiajs.com
MIT License
10.59k stars 226 forks source link

There is not custom http exception in elysia #910

Open DeepanshuKacher opened 2 weeks ago

DeepanshuKacher commented 2 weeks ago

What is the problem this feature would solve?

Previously I was using nest.js in node.js enviornment now testing bun.js and elysia for my new project, elysia is good but when it comes to error handeling elysia don't give any custom http exception

for example here is hono code :-


import { HTTPException } from 'hono/http-exception'

app.post('/auth', async (c, next) => {
  // authentication
  if (authorized === false) {
    throw new HTTPException(401, { message: 'Custom error message' })
  }
  await next()
})

it's similar to nest.js where developer have the ablitiy to throw error message with status code elysia lack that functionality

I know elysia have 3 http exceptions like Internal Server Exception, Conflict and NotFound, but those are not enough, having a custom http exception which give ability to developer to throw error with status code is required.

What is the feature you are proposing to solve the problem?

Developer will have to ability to throw http exception with proper status code.

Required features for headless cms

A proper error status code tells a lot for some front-end network request libraries like axios, also helpful for debugging process

What alternatives have you considered?

No response

Scooter1337 commented 2 weeks ago
throw error(401, { message: 'Custom error message' });

But custom error messages are better: https://elysiajs.com/essential/life-cycle.html#custom-error