From 4c4dbdc6250d907adc5cadab7ab2ce142e216213 Mon Sep 17 00:00:00 2001 From: arthurfiorette Date: Mon, 18 Sep 2023 17:12:22 -0300 Subject: [PATCH 1/8] ci --- .github/workflows/ci.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..443d7f70 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,25 @@ +name: Code CI + +on: + push: + pull_request: + +jobs: + build: + name: Build and test code + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup bun + uses: oven-sh/setup-bun@v1 + with: + bun-version: latest + + - name: Install packages + run: bun install + + - name: Test + run: bun test From 2ac9171fd39d1e2ecef9f270484138ddbfee3f10 Mon Sep 17 00:00:00 2001 From: Arthur Fiorette Date: Mon, 18 Sep 2023 17:20:09 -0300 Subject: [PATCH 2/8] node tests --- .github/workflows/ci.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 443d7f70..8c1f96be 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,8 +18,13 @@ jobs: with: bun-version: latest + - name: Setup node and restore cached dependencies + uses: actions/setup-node@v3 + with: + node-version: '20' + - name: Install packages run: bun install - name: Test - run: bun test + run: bun run test From 7039e55bfac62515209c5b9dee2a940fb97bf80f Mon Sep 17 00:00:00 2001 From: Arthur Fiorette Date: Mon, 18 Sep 2023 17:30:13 -0300 Subject: [PATCH 3/8] Create dependabot.yml --- .github/dependabot.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..886beac6 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,11 @@ +version: 2 +updates: + - package-ecosystem: 'npm' + directory: './' + schedule: + interval: 'daily' + + - package-ecosystem: 'github-actions' + directory: './' + schedule: + interval: 'daily' From 9afe3f1149dd36d7b8fffe11d3b650b640f3a807 Mon Sep 17 00:00:00 2001 From: Arthur Fiorette Date: Mon, 18 Sep 2023 17:30:31 -0300 Subject: [PATCH 4/8] Update ci.yml --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8c1f96be..e366f605 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,5 +26,8 @@ jobs: - name: Install packages run: bun install + - name: Build code + run: bun run build + - name: Test run: bun run test From 5f6e54f34228521262a19cac6dd819f1f750ac35 Mon Sep 17 00:00:00 2001 From: Arthur Fiorette Date: Mon, 18 Sep 2023 17:41:41 -0300 Subject: [PATCH 5/8] Update ci.yml --- .github/workflows/ci.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e366f605..877f4d3d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,11 +18,6 @@ jobs: with: bun-version: latest - - name: Setup node and restore cached dependencies - uses: actions/setup-node@v3 - with: - node-version: '20' - - name: Install packages run: bun install From 9ddb3e8aed3fe6239894c6fd33fed04f30f61868 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 19 Sep 2023 05:15:55 +0000 Subject: [PATCH 6/8] build(deps): bump actions/checkout from 3 to 4 Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/publish.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 0445bf85..5393322f 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -19,7 +19,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 @@ -39,7 +39,7 @@ jobs: runs-on: ubuntu-latest steps: - name: 'Checkout' - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: 'Setup Bun' uses: oven-sh/setup-bun@v1 From fc1a218402f1fcd74cceff2c9d181d6596ce3fd9 Mon Sep 17 00:00:00 2001 From: Brayden Date: Tue, 19 Sep 2023 03:15:46 -0400 Subject: [PATCH 7/8] my PR got merged and closed somehow??? --- src/error.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/error.ts b/src/error.ts index e6a37807..e4e9c14e 100644 --- a/src/error.ts +++ b/src/error.ts @@ -20,11 +20,12 @@ export type ElysiaErrors = | ValidationError export class InternalServerError extends Error { - code = 'NOT_FOUND' + code = 'INTERNAL_SERVER_ERROR' status = 500 - constructor() { - super('INTERNAL_SERVER_ERROR') + constructor(message: string) + constructor(message?: string) { + super(message ?? 'INTERNAL_SERVER_ERROR') } } @@ -32,8 +33,9 @@ export class NotFoundError extends Error { code = 'NOT_FOUND' status = 404 - constructor() { - super('NOT_FOUND') + constructor(message: string) + constructor(message?: string) { + super(message ?? 'NOT_FOUND') } } @@ -41,8 +43,9 @@ export class ParseError extends Error { code = 'PARSE' status = 400 - constructor() { - super('PARSE') + constructor(message: string) + constructor(message?: string) { + super(message ?? 'PARSE') } } From 9e9a3bb467f1556f5e0ff40ba2ebf8c874ac1c58 Mon Sep 17 00:00:00 2001 From: bogeychan Date: Tue, 19 Sep 2023 13:43:57 +0200 Subject: [PATCH 8/8] fix: `InternalServerError` code --- src/error.ts | 2 +- test/error.test.ts | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/error.ts b/src/error.ts index e6a37807..8d7320fa 100644 --- a/src/error.ts +++ b/src/error.ts @@ -20,7 +20,7 @@ export type ElysiaErrors = | ValidationError export class InternalServerError extends Error { - code = 'NOT_FOUND' + code = 'INTERNAL_SERVER_ERROR' status = 500 constructor() { diff --git a/test/error.test.ts b/test/error.test.ts index 34a12541..aa2ac8a0 100644 --- a/test/error.test.ts +++ b/test/error.test.ts @@ -1,4 +1,4 @@ -import { Elysia, t } from '../src' +import { Elysia, InternalServerError, t } from '../src' import { describe, expect, it } from 'bun:test' import { post, req } from './utils' @@ -48,4 +48,21 @@ describe('error', () => { expect(data.length).toBe(4) expect(res.status).toBe(400) }) + + it('custom 500', async () => { + const app = new Elysia() + .onError(({ code }) => { + if (code === 'INTERNAL_SERVER_ERROR') { + return 'UwU' + } + }) + .get('/', () => { + throw new InternalServerError() + }) + + const response = await app.handle(req('/')) + + expect(await response.text()).toBe('UwU') + expect(response.status).toBe(500) + }) })