-
Notifications
You must be signed in to change notification settings - Fork 7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5599 from Alanscut:issue_4985
[feature] Enable exceptions for invali moments Fixes #4985
- Loading branch information
Showing
8 changed files
with
146 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
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
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,54 @@ | ||
import { hooks } from './hooks'; | ||
import isDate from './is-date'; | ||
|
||
/** | ||
* Update an Error with the specified date, input and format. | ||
* | ||
* @param {*} message The error message | ||
* @param {*} date The date | ||
* @param {*} input The input | ||
* @param {*} format The format | ||
*/ | ||
function makeError(message, date, input, format) { | ||
var error = new Error(message); | ||
error.date = date; | ||
error.input = input; | ||
error.format = format; | ||
error.toJSON = function toJSON() { | ||
return { | ||
// Standard | ||
message: this.message, | ||
name: this.name, | ||
// Microsoft | ||
description: this.description, | ||
number: this.number, | ||
// Mozilla | ||
fileName: this.fileName, | ||
lineNumber: this.lineNumber, | ||
columnNumber: this.columnNumber, | ||
stack: this.stack, | ||
}; | ||
}; | ||
return error; | ||
} | ||
|
||
/** | ||
* Create an Error with the specified message, date, input and format. | ||
* | ||
* @param {*} message The error message | ||
* @param {*} date The date | ||
* @param {*} input The input | ||
* @param {*} format The format | ||
*/ | ||
export default function createError(message, date, input, format) { | ||
if (hooks.suppressCreateError !== false) { | ||
return; | ||
} | ||
if (isDate(date) && date.toString() !== 'Invalid Date') { | ||
return; | ||
} | ||
throw makeError(message, date, input, format); | ||
} | ||
|
||
// Specify whether to disable throwing errors, ths default value is `true` | ||
hooks.suppressCreateError = true; |
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