-
-
Notifications
You must be signed in to change notification settings - Fork 147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle 412 response #203
Comments
@armpogart Any info as to what your server is? Nextcloud or something? Thanks. |
@perry-mitchell Not sure, I'm using the library on some SAAS service which provides dav access for storage. The only thing I see is that they are using |
I encountered a similar error in the function await client.putFileContents(path, message + '\n', { overwrite: false }); If file not exists -- Ok, if file exists -- error: // box.com
{
config: {
url: 'https://dav.box.com/dav/test/test.txt',
method: 'put',
data: 'String 2\n',
headers: {
Accept: 'application/json, text/plain, */*',
'Content-Type': 'application/octet-stream',
'Content-Length': 9,
Authorization: 'Basic XXX=',
'If-None-Match': '*',
'User-Agent': 'axios/0.19.2'
},
timeout: 0,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
},
// ...
response: {
status: 412,
statusText: 'Precondition Failed',
headers: {
date: 'Mon, 08 Jun 2020 07:34:28 GMT',
'content-type': 'application/xml',
'content-length': '320',
connection: 'close',
'x-envoy-upstream-service-time': '133',
'strict-transport-security': 'max-age=31536000'
},
config: {
url: 'https://dav.box.com/dav/test/test.txt',
method: 'put',
data: 'String 2\n',
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
},
data: '<?xml version="1.0" encoding="utf-8"?>\n' +
'<d:error xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">\n' +
' <s:exception>Sabre_DAV_Exception_PreconditionFailed</s:exception>\n' +
' <s:message>An If-None-Match header was specified, but the ETag matched (or * was specified).</s:message>\n' +
' <s:header>If-None-Match</s:header>\n' +
'</d:error>\n'
},
isAxiosError: true,
} // yandex.ru
{
config: {
url: 'https://webdav.yandex.ru/test/test.txt',
method: 'put',
data: 'String 2\n',
headers: {
Accept: 'application/json, text/plain, */*',
'Content-Type': 'application/octet-stream',
'Content-Length': 9,
Authorization: 'Basic XXX==',
'If-None-Match': '*',
'User-Agent': 'axios/0.19.2'
},
timeout: 0,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
},
// ...
response: {
status: 412,
statusText: 'Precondition Failed',
headers: {
connection: 'close',
date: 'Mon, 08 Jun 2020 10:26:20 GMT',
'yandex-cloud-request-id': 'dav-XXX',
'yandex-uid': 'XXX',
'x-frame-options': 'SAMEORIGIN',
'x-xss-protection': '1; mode=block',
'x-content-type-options': 'nosniff',
server: 'Jetty(9.4.11.v20180605)'
},
config: {
url: 'https://webdav.yandex.ru/test/test.txt',
method: 'put',
data: 'String 2\n',
timeout: 0,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
},
data: ''
},
isAxiosError: true,
} |
@perry-mitchell After further digging into the problem I've found out that server is responding correctly and the problem is in the client (this library). From RFC7232 on Conditional Requests you can see following excerpt:
and so the server responds with 412 which means that it has a current representation for the target resource (in our case file that we want to upload). But in this implementation we can see the code that throws error if the response error code >= 400. I'm not sure how or on which server this method was tested with overwrite, and if the test succeeded it simply meant that the server wasn't correctly implementing HTTP RFC. @perry-mitchell Would you accept PR on this one? Is it sufficient to just return the response with that status code in that case and exclude it from P.S. If there is no any precondition check with ETag specified (and as far as I see there is none) my proposed change will be ok. If ETag is used anywhere |
While using
putFileContents('path', buffer, { overwrite: false })
I get following error:Request failed with status code 412
.P.S. Without
{ overwrite: false }
everything works, but obviously it just overwrites the files, but I need to not overwrite files if they exist. Desktop clients (such as WinSCP and Cyberduck) successfully detect existing files and don't overwrite them if requested. I do not have control over DAV server.The full error object is the following (sensitive information stripped):
The text was updated successfully, but these errors were encountered: