Skip to content

Commit

Permalink
Move error handling to after the param formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Spencer Sablan committed May 3, 2024
1 parent f6511f9 commit 9663659
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/paypal-js/src/load-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ export function loadScript(
// resolve with null when running in Node or Deno
if (typeof document === "undefined") return PromisePonyfill.resolve(null);

if (!options.clientId) {
const { url, attributes, queryParams } = processOptions(options);

if (!queryParams["client-id"]) {
throw new Error(
`Expected clientId in options object: ${JSON.stringify(options)}`
);
}

const { url, attributes } = processOptions(options);

const namespace = attributes["data-namespace"] || "paypal";
const existingWindowNamespace = getPayPalWindowNamespace(namespace);

Expand Down
2 changes: 2 additions & 0 deletions packages/paypal-js/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export function insertScriptElement({
export function processOptions(options: PayPalScriptOptions): {
url: string;
attributes: StringMap;
queryParams: StringMap;
} {
const { environment } = options;
// Keeping production as default to maintain backward compatibility.
Expand Down Expand Up @@ -121,6 +122,7 @@ export function processOptions(options: PayPalScriptOptions): {
return {
url: `${sdkBaseUrl}?${objectToQueryString(queryParams)}`,
attributes,
queryParams,
};
}

Expand Down

0 comments on commit 9663659

Please sign in to comment.