Skip to content

Commit

Permalink
Merge pull request #4722 from coralproject/develop
Browse files Browse the repository at this point in the history
v9.6.2
  • Loading branch information
tessalt authored Jan 15, 2025
2 parents d399c8e + b5dfc7b commit 33d89fc
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 26 deletions.
4 changes: 2 additions & 2 deletions client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@coralproject/talk",
"version": "9.6.1",
"version": "9.6.2",
"author": "The Coral Project",
"homepage": "https://coralproject.net/",
"sideEffects": [
Expand All @@ -22,7 +22,7 @@
"description": "A better commenting experience from Vox Media.",
"scripts": {
"build:client": "NODE_OPTIONS=\"--openssl-legacy-provider --no-experimental-fetch\" ts-node --transpile-only ./scripts/build.ts",
"build:development": "NODE_OPTIONS=\"--openssl-legacy-provider --no-experimental-fetch\" NODE_ENV=development pnpm run --parallel generate build:client",
"build:development": "NODE_OPTIONS=\"--openssl-legacy-provider --no-experimental-fetch\" NODE_ENV=development pnpm run generate && pnpm run build:client",
"build:withProfiler": "NODE_ENV=production REACT_PROFILER=true pnpm run --parallel generate build:client",
"build": "NODE_OPTIONS=\"--openssl-legacy-provider --no-experimental-fetch\" NODE_ENV=production pnpm run generate-persist && pnpm run build:client",
"docs:css-variables": "ts-node ./scripts/generateCSSVariablesDocs.ts ./src/core/client/ui/theme/streamVariables.ts ./CSS_VARIABLES.md",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,80 @@ import { RRNLRequestError } from "react-relay-network-modern/es";

import { getMessage } from "../i18n";

interface DupErrorObj {
error?: {
traceID: string;
code: string;
message: string;
};
}

const parseDuplicateEmailError = (
error: RRNLRequestError
): DupErrorObj | null => {
if (!error.res || error.res.status !== 403 || !error.res.text) {
return null;
}

try {
const json = JSON.parse(error.res.text) as DupErrorObj;
if (!json || !json.error || json.error.code !== "DUPLICATE_EMAIL") {
return null;
}

return json;
} catch {
return null;
}
};

const computeCodeMessage = (
error: RRNLRequestError,
localeBundles: FluentBundle[]
) => {
if (!error.res) {
return "";
}

const codePrefix = getMessage(
localeBundles,
"framework-error-relayNetworkRequestError-code",
"Code"
);

let msg = `[${codePrefix}]`;
if (error.res && error.res.status) {
msg += ` ${error.res.status.toString()}`;
}
if (error.res && error.res.statusText) {
msg += ` ${error.res.statusText}`;
}

return msg;
};

const computeMessage = (
error: RRNLRequestError,
localeBundles: FluentBundle[]
): string => {
const defaultMessage = getMessage(
localeBundles,
"framework-error-relayNetworkRequestError-anUnexpectedNetworkError",
"An unexpected network error occured, please try again later."
);

const dupeEmail = parseDuplicateEmailError(error);
if (dupeEmail && dupeEmail.error) {
return dupeEmail.error.message;
}

if (error.res) {
return `${defaultMessage} ${computeCodeMessage(error, localeBundles)}`;
}

return defaultMessage;
};

/**
* RelayNetworkRequestError wraps Request errors thrown by Relay Network Layer.
*/
Expand All @@ -11,26 +85,7 @@ export default class RelayNetworkRequestError extends Error {
public origin: RRNLRequestError;

constructor(error: RRNLRequestError, localeBundles: FluentBundle[]) {
let msg = getMessage(
localeBundles,
"framework-error-relayNetworkRequestError-anUnexpectedNetworkError",
"An unexpected network error occured, please try again later."
);

if (error.res) {
const codePrefix = getMessage(
localeBundles,
"framework-error-relayNetworkRequestError-code",
"Code"
);

msg += ` [${codePrefix}: ${error.res.status.toString()}`;
if (error.res.statusText) {
msg += " " + error.res.statusText;
}
msg += "]";
}
super(msg);
super(computeMessage(error, localeBundles));

// Maintains proper stack trace for where our error was thrown.
if (Error.captureStackTrace) {
Expand Down
2 changes: 1 addition & 1 deletion common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "common",
"version": "9.6.1",
"version": "9.6.2",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion config/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "common",
"version": "9.6.1",
"version": "9.6.2",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@coralproject/talk",
"version": "9.6.1",
"version": "9.6.2",
"author": "The Coral Project",
"homepage": "https://coralproject.net/",
"sideEffects": [
Expand Down
6 changes: 5 additions & 1 deletion server/src/core/server/errors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,11 @@ export class DuplicateSiteAllowedOriginError extends CoralError {

export class DuplicateEmailError extends CoralError {
constructor(email: string) {
super({ code: ERROR_CODES.DUPLICATE_EMAIL, context: { pvt: { email } } });
super({
code: ERROR_CODES.DUPLICATE_EMAIL,
context: { pvt: { email } },
status: 403,
});
}
}

Expand Down

0 comments on commit 33d89fc

Please sign in to comment.