Skip to content

Instantly share code, notes, and snippets.

@lavelle
Last active August 29, 2015 14:06
Show Gist options
  • Save lavelle/8b3ac02af93e25d9dd7f to your computer and use it in GitHub Desktop.
Save lavelle/8b3ac02af93e25d9dd7f to your computer and use it in GitHub Desktop.
FSP error code mapping
/**
* WebDAV error code map.
* All taken from http://msdn.microsoft.com/en-us/library/aa142917(v=exchg.65).aspx
* @const
* @type {Object}
*/
var ERROR_MAP = {
DELETE: {
'204': 'OK',
'423': 'IN_USE'
},
MOVE: {
'201': 'OK',
'204': 'OK',
'403': 'INVALID_OPERATION',
'409': 'FAILED',
'412': 'EXISTS',
'423': 'IN_USE',
'502': 'ACCESS_DENIED'
},
COPY: {
'201': 'OK',
'204': 'OK',
'403': 'INVALID_OPERATION',
'409': 'FAILED',
'412': 'EXISTS',
'423': 'IN_USE',
'502': 'ACCESS_DENIED',
'507': 'NO_SPACE'
}
};
/**
* Converts a HTTP error code into its equivalent code for the FSP API.
* @param {number} code The HTTP verb for the request.
* @param {number} code The HTTP error code.
* @return {string} The FSP error code.
*/
var getError = function(verb, code) {
code = '' + code;
if (verb in ERROR_MAP) {
var map = ERROR_MAP[verb];
if (code in map) {
return map[code];
} else {
return 'FAILED';
}
} else {
throw new Error('Invalid HTTP verb: ' + verb);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment