Skip to content

Commit

Permalink
fix(auth): pass App Store Server API error message to registration en…
Browse files Browse the repository at this point in the history
…dpoint caller

Because:

* When migrating existing Apple IAP users, some users failed to migrate, and any App Store Server API error we got would be transformed into a 400 "Invalid token" with no additional details.

This commit:

* Passes the exact App Store Server API error message to the registration endpoint caller, which will indicate if the error is retryable for example.

Closes #FXA-6459
  • Loading branch information
biancadanforth authored and vbudhram committed Jan 17, 2023
1 parent f28856c commit d422909
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/fxa-auth-server/lib/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -1418,7 +1418,7 @@ AppError.iapInvalidToken = (error) => {
code: 400,
error: 'Bad Request',
errno: ERRNO.IAP_INVALID_TOKEN,
message: 'Invalid token',
message: `Invalid IAP token${error?.message ? `: ${error.message}` : ''}`,
},
...extra
);
Expand Down
21 changes: 21 additions & 0 deletions packages/fxa-auth-server/test/local/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,27 @@ describe('AppErrors', () => {
assert(!result.output.payload.retryAfterLocalized);
});

it('iapInvalidToken', () => {
const defaultErrorMessage = 'Invalid IAP token';
let result = AppError.iapInvalidToken();
assert.ok(result instanceof AppError, 'instanceof AppError');
assert.equal(result.errno, 196);
assert.equal(result.message, defaultErrorMessage);
assert.equal(result.output.statusCode, 400);
assert.equal(result.output.payload.error, 'Bad Request');

let iapAPIError = { someProp: 123 };
result = AppError.iapInvalidToken(iapAPIError);
assert.equal(result.message, defaultErrorMessage);

iapAPIError = { message: 'Wow helpful extra info' };
result = AppError.iapInvalidToken(iapAPIError);
assert.equal(
result.message,
`${defaultErrorMessage}: ${iapAPIError.message}`
);
});

it('unexpectedError without request data', () => {
const err = AppError.unexpectedError();
assert.instanceOf(err, AppError);
Expand Down

0 comments on commit d422909

Please sign in to comment.