Skip to content

Commit

Permalink
🔧 fix(treaty2): use null as default data value
Browse files Browse the repository at this point in the history
  • Loading branch information
SaltyAom committed Mar 20, 2024
1 parent 1d95b1b commit b10c17b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.0.5 - 20 Mar 2024
Change:
- treaty2: use null as default data value instead of undefined

# 1.0.4 - 18 Mar 2024
Bug fix:
- Using regex for date pattern matching
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@elysiajs/eden",
"version": "1.0.4",
"version": "1.0.5",
"description": "Fully type-safe Elysia client",
"author": {
"name": "saltyAom",
Expand Down
8 changes: 4 additions & 4 deletions src/treaty2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ const createProxy = (
new Request(url, fetchInit)
) ?? fetcher!(url, fetchInit))

let data
let data = null
let error

if (onResponse) {
Expand All @@ -298,7 +298,7 @@ const createProxy = (
try {
data = await value(response.clone())

if (data !== undefined) break
if (data !== undefined && data !== null) break
} catch (err) {
if (err instanceof EdenFetchError) error = err
else error = new EdenFetchError(422, err)
Expand All @@ -307,7 +307,7 @@ const createProxy = (
}
}

if (data === undefined) {
if (data === null) {
switch (
response.headers.get('Content-Type')?.split(';')[0]
) {
Expand Down Expand Up @@ -346,7 +346,7 @@ const createProxy = (

if (response.status >= 300 || response.status < 200) {
error = new EdenFetchError(response.status, data)
data = undefined
data = null
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/treaty2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ describe('Treaty2', () => {
break
}

expect(data).toBeUndefined()
expect(data).toBeNull()
expect(value).toEqual('Kirifuji Nagisa')
})

Expand Down

0 comments on commit b10c17b

Please sign in to comment.