fix(upload): errorFromDirectUploadMessage should take Error or string

This commit is contained in:
Paul Chavard 2022-04-24 11:47:17 +02:00
parent f70344b89b
commit bca97268a8
2 changed files with 4 additions and 2 deletions

View file

@ -63,7 +63,9 @@ export default class FileUploadError extends Error {
// 2. Create each kind of error on a different line
// (so that Sentry knows they are different kind of errors, from
// the line they were created.)
export function errorFromDirectUploadMessage(message: string) {
export function errorFromDirectUploadMessage(messageOrError: string | Error) {
const message =
typeof messageOrError == 'string' ? messageOrError : messageOrError.message;
const matches = message.match(/ Status: ([0-9]{1,3})/);
const status = matches ? parseInt(matches[1], 10) : undefined;

View file

@ -60,7 +60,7 @@ export default class Uploader {
return new Promise((resolve, reject) => {
this.directUpload.create((errorMsg, attributes) => {
if (errorMsg) {
const error = errorFromDirectUploadMessage(errorMsg.message);
const error = errorFromDirectUploadMessage(errorMsg);
reject(error);
} else {
resolve(attributes.signed_id);