-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
37 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
function isForbidden(inner) { | ||
return inner && (inner.code === "Forbidden" || inner.statusCode === 403); | ||
} | ||
|
||
export default class S3Error extends Error { | ||
|
||
/** | ||
* @param {Object} inner AWS inner error | ||
*/ | ||
constructor(inner) { | ||
|
||
let subMessage = inner.message; | ||
if (!subMessage && isForbidden(inner)) { | ||
subMessage = "No access (make sure you have access to S3 ressource, and have valid policies)"; | ||
} | ||
|
||
let message = `S3 ${inner.code} (${inner.statusCode})`; | ||
if (subMessage) { | ||
message = `${message}: ${subMessage}`; | ||
} | ||
|
||
super(message); | ||
Error.captureStackTrace(this, this.constructor); | ||
this.name = this.constructor.name; | ||
this.inner = inner; | ||
} | ||
|
||
} |