forked from microsoft/FluidFramework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
odspError.ts
40 lines (37 loc) · 1.66 KB
/
odspError.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*!
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
* Licensed under the MIT License.
*/
import { createOdspNetworkError } from "@fluidframework/odsp-doclib-utils";
import { DriverErrorType } from "@fluidframework/driver-definitions";
import { NonRetryableError } from "@fluidframework/driver-utils";
import { OdspError } from "@fluidframework/odsp-driver-definitions";
import { getCircularReplacer, IFluidErrorBase } from "@fluidframework/telemetry-utils";
import { IOdspSocketError } from "./contracts";
import { pkgVersion as driverVersion } from "./packageVersion";
/**
* Returns network error based on error object from ODSP socket (IOdspSocketError)
*/
export function errorObjectFromSocketError(socketError: IOdspSocketError, handler: string):
IFluidErrorBase & OdspError {
// Make sure we always return something, and do not throw.
try {
// pre-0.58 error message prefix: OdspSocketError
const message = `ODSP socket error (${handler}): ${socketError.message}`;
const error = createOdspNetworkError(
message,
socketError.code,
socketError.retryAfter,
undefined, // response from http request
socketError.error ?
JSON.stringify({ error: socketError.error }, getCircularReplacer()) : undefined, // responseText
);
error.addTelemetryProperties({ odspError: true, relayServiceError: true });
return error;
} catch (error) {
return new NonRetryableError(
"Internal error: errorObjectFromSocketError",
DriverErrorType.fileNotFoundOrAccessDeniedError,
{ driverVersion });
}
}