-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: match edge function error codes to hosted platform (#2887)
- Loading branch information
Showing
1 changed file
with
21 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,30 @@ | ||
import { | ||
STATUS_CODE, | ||
STATUS_TEXT, | ||
} from "https://deno.land/std/http/status.ts"; | ||
import { STATUS_CODE, STATUS_TEXT } from "https://deno.land/std/http/status.ts"; | ||
import * as posix from "https://deno.land/std/path/posix/mod.ts"; | ||
|
||
import * as jose from "https://deno.land/x/[email protected]/index.ts"; | ||
|
||
const SB_SPECIFIC_ERROR_CODE = { | ||
BootError: STATUS_CODE.ServiceUnavailable, /** Service Unavailable (RFC 7231, 6.6.4) */ | ||
WorkerRequestCancelled: STATUS_CODE.BadGateway, /** Bad Gateway (RFC 7231, 6.6.3) */ | ||
BootError: | ||
STATUS_CODE.ServiceUnavailable, /** Service Unavailable (RFC 7231, 6.6.4) */ | ||
InvalidWorkerResponse: | ||
STATUS_CODE.InternalServerError, /** Internal Server Error (RFC 7231, 6.6.1) */ | ||
WorkerLimit: 546, /** Extended */ | ||
}; | ||
|
||
const SB_SPECIFIC_ERROR_TEXT = { | ||
[SB_SPECIFIC_ERROR_CODE.BootError]: "BOOT_ERROR", | ||
[SB_SPECIFIC_ERROR_CODE.WorkerRequestCancelled]: "WORKER_REQUEST_CANCELLED", | ||
[SB_SPECIFIC_ERROR_CODE.InvalidWorkerResponse]: "WORKER_ERROR", | ||
[SB_SPECIFIC_ERROR_CODE.WorkerLimit]: "WORKER_LIMIT", | ||
}; | ||
|
||
const SB_SPECIFIC_ERROR_REASON = { | ||
[SB_SPECIFIC_ERROR_CODE.BootError]: "Worker failed to boot (please check logs)", | ||
[SB_SPECIFIC_ERROR_CODE.WorkerRequestCancelled]: "Request cancelled by the proxy due to an error or resource limit of worker (please check logs)", | ||
[SB_SPECIFIC_ERROR_CODE.WorkerLimit]: "Worker failed to respond due to an error or resource limit (please check logs)", | ||
} | ||
[SB_SPECIFIC_ERROR_CODE.BootError]: | ||
"Worker failed to boot (please check logs)", | ||
[SB_SPECIFIC_ERROR_CODE.InvalidWorkerResponse]: | ||
"Function exited due to an error (please check logs)", | ||
[SB_SPECIFIC_ERROR_CODE.WorkerLimit]: | ||
"Worker failed to respond due to a resource limit (please check logs)", | ||
}; | ||
|
||
// OS stuff - we don't want to expose these to the functions. | ||
const EXCLUDED_ENVS = ["HOME", "HOSTNAME", "PATH", "PWD"]; | ||
|
@@ -34,12 +36,17 @@ const FUNCTIONS_CONFIG_STRING = Deno.env.get( | |
"SUPABASE_INTERNAL_FUNCTIONS_CONFIG", | ||
)!; | ||
|
||
const WALLCLOCK_LIMIT_SEC = parseInt(Deno.env.get("SUPABASE_INTERNAL_WALLCLOCK_LIMIT_SEC")); | ||
const WALLCLOCK_LIMIT_SEC = parseInt( | ||
Deno.env.get("SUPABASE_INTERNAL_WALLCLOCK_LIMIT_SEC"), | ||
); | ||
|
||
const DENO_SB_ERROR_MAP = new Map([ | ||
[Deno.errors.InvalidWorkerCreation, SB_SPECIFIC_ERROR_CODE.BootError], | ||
[Deno.errors.InvalidWorkerResponse, SB_SPECIFIC_ERROR_CODE.WorkerLimit], | ||
[Deno.errors.WorkerRequestCancelled, SB_SPECIFIC_ERROR_CODE.WorkerRequestCancelled], | ||
[Deno.errors.InvalidWorkerResponse, SB_SPECIFIC_ERROR_CODE.InvalidWorkerResponse], | ||
[ | ||
Deno.errors.WorkerRequestCancelled, | ||
SB_SPECIFIC_ERROR_CODE.WorkerLimit, | ||
], | ||
]); | ||
|
||
interface FunctionConfig { | ||
|