Skip to content

Commit

Permalink
Respond with actuall error code and message received from Apple server
Browse files Browse the repository at this point in the history
  • Loading branch information
nicupavel committed Jan 30, 2023
1 parent 6237e5b commit cd6ddc6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-apple-weatherkit",
"version": "1.2.0",
"version": "1.3.0",
"description": "Apple WeatherKit API node.js implementation",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
Expand Down
4 changes: 2 additions & 2 deletions src/api/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export default class Api {
},
})

if (response.status >= 400) {
return Err(`API Fail for ${url}`)
if (response.status != 200) {
return Err(await response.text(), response.status)
}

return (await response.json()) as T
Expand Down
5 changes: 3 additions & 2 deletions src/types/Err.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
export type Err = {
isErr: true
error: unknown
code: number
}

export function Err(message: string): Err {
return { isErr: true, error: message }
export function Err(message: string, code: number): Err {
return { isErr: true, error: message, code: code }
}

export function isErr(err: unknown): err is Err {
Expand Down

0 comments on commit cd6ddc6

Please sign in to comment.