-
Notifications
You must be signed in to change notification settings - Fork 9
refactor: use HTTP status code descriptions in files plugin #258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| import { STATUS_CODES } from "node:http"; | ||
| import { Readable } from "node:stream"; | ||
| import { ApiError } from "@databricks/sdk-experimental"; | ||
| import type express from "express"; | ||
|
|
@@ -448,7 +449,10 @@ export class FilesPlugin extends Plugin { | |
| if (!result.ok) { | ||
| res | ||
| .status(result.status) | ||
| .json({ error: "List failed", plugin: this.name }); | ||
| .json({ | ||
| error: STATUS_CODES[result.status] ?? "Unknown Error", | ||
| plugin: this.name, | ||
| }); | ||
| return; | ||
| } | ||
| res.json(result.data); | ||
|
|
@@ -486,7 +490,10 @@ export class FilesPlugin extends Plugin { | |
| if (!result.ok) { | ||
| res | ||
| .status(result.status) | ||
| .json({ error: "Read failed", plugin: this.name }); | ||
| .json({ | ||
| error: STATUS_CODES[result.status] ?? "Unknown Error", | ||
| plugin: this.name, | ||
| }); | ||
| return; | ||
| } | ||
| res.type("text/plain").send(result.data); | ||
|
|
@@ -552,7 +559,10 @@ export class FilesPlugin extends Plugin { | |
| if (!response.ok) { | ||
| res | ||
| .status(response.status) | ||
| .json({ error: `${label} failed`, plugin: this.name }); | ||
| .json({ | ||
| error: STATUS_CODES[response.status] ?? "Unknown Error", | ||
| plugin: this.name, | ||
| }); | ||
|
||
| return; | ||
| } | ||
|
|
||
|
|
@@ -633,7 +643,10 @@ export class FilesPlugin extends Plugin { | |
| if (!result.ok) { | ||
| res | ||
| .status(result.status) | ||
| .json({ error: "Exists check failed", plugin: this.name }); | ||
| .json({ | ||
| error: STATUS_CODES[result.status] ?? "Unknown Error", | ||
| plugin: this.name, | ||
| }); | ||
| return; | ||
| } | ||
| res.json({ exists: result.data }); | ||
|
|
@@ -671,7 +684,10 @@ export class FilesPlugin extends Plugin { | |
| if (!result.ok) { | ||
| res | ||
| .status(result.status) | ||
| .json({ error: "Metadata fetch failed", plugin: this.name }); | ||
| .json({ | ||
| error: STATUS_CODES[result.status] ?? "Unknown Error", | ||
| plugin: this.name, | ||
| }); | ||
| return; | ||
| } | ||
| res.json(result.data); | ||
|
|
@@ -709,7 +725,10 @@ export class FilesPlugin extends Plugin { | |
| if (!result.ok) { | ||
| res | ||
| .status(result.status) | ||
| .json({ error: "Preview failed", plugin: this.name }); | ||
| .json({ | ||
| error: STATUS_CODES[result.status] ?? "Unknown Error", | ||
| plugin: this.name, | ||
| }); | ||
| return; | ||
| } | ||
| res.json(result.data); | ||
|
|
@@ -809,7 +828,10 @@ export class FilesPlugin extends Plugin { | |
| ); | ||
| res | ||
| .status(result.status) | ||
| .json({ error: "Upload failed", plugin: this.name }); | ||
| .json({ | ||
| error: STATUS_CODES[result.status] ?? "Unknown Error", | ||
| plugin: this.name, | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
|
|
@@ -864,7 +886,10 @@ export class FilesPlugin extends Plugin { | |
| if (!result.ok) { | ||
| res | ||
| .status(result.status) | ||
| .json({ error: "Create directory failed", plugin: this.name }); | ||
| .json({ | ||
| error: STATUS_CODES[result.status] ?? "Unknown Error", | ||
| plugin: this.name, | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
|
|
@@ -911,7 +936,10 @@ export class FilesPlugin extends Plugin { | |
| if (!result.ok) { | ||
| res | ||
| .status(result.status) | ||
| .json({ error: "Delete failed", plugin: this.name }); | ||
| .json({ | ||
| error: STATUS_CODES[result.status] ?? "Unknown Error", | ||
| plugin: this.name, | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The status-to-message mapping logic is duplicated across multiple handlers (list/read/exists/metadata/preview/upload/mkdir/delete). Consider extracting a small helper (e.g.,
this._statusDescription(status)orthis._sendStatusError(res, status)) to avoid repetition and ensure consistent behavior (including what to do for unknown/non-standard status codes).