Skip to content

Commit

Permalink
Make http driver return null when item not found
Browse files Browse the repository at this point in the history
  • Loading branch information
Aareksio committed Jan 6, 2024
1 parent cc21612 commit f42ec6c
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions src/drivers/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,34 @@ export default defineDriver((opts: HTTPOptions) => {
.catch(() => false);
},
async getItem(key, tops = {}) {
const value = await _fetch(r(key), {
headers: { ...opts.headers, ...tops.headers },
});
return value;
try {
return await _fetch(r(key), {
headers: { ...opts.headers, ...tops.headers },
});
} catch (err: any) {
if (err?.response?.status === 404) {
return null;
}

throw err;
}

Check warning on line 40 in src/drivers/http.ts

View check run for this annotation

Codecov / codecov/patch

src/drivers/http.ts#L38-L40

Added lines #L38 - L40 were not covered by tests
},
async getItemRaw(key, topts) {
const value = await _fetch(r(key), {
headers: {
accept: "application/octet-stream",
...opts.headers,
...topts.headers,
},
});
return value;
try {
return await await _fetch(r(key), {
headers: {
accept: "application/octet-stream",
...opts.headers,
...topts.headers,
},
});
} catch (err: any) {
if (err?.response?.status === 404) {
return null;
}

throw err;
}

Check warning on line 57 in src/drivers/http.ts

View check run for this annotation

Codecov / codecov/patch

src/drivers/http.ts#L52-L57

Added lines #L52 - L57 were not covered by tests
},
async getMeta(key, topts) {
const res = await _fetch.raw(r(key), {
Expand Down

0 comments on commit f42ec6c

Please sign in to comment.