1

I'm trying to return an error from my AJAX page but no matter how I format it it's not seen as an error and the Promise continues unabated. The only way to actually trigger the catch is sending bad JSON (which is unhelpful) or a bad URL. This is not specific to Classic ASP but the app I'm trying to help fix uses that so that's where this example comes from:

Response.ContentType = "application/vnd.api+json"
Response.CharSet = "UTF-8"
Response.LCID = 1033

Response.Status "409 Conflict"
Response.Write "{ ""errors"": [ { ""status"": ""409"", ""source"": { ""pointer"": ""Error in new name"" }, ""title"": ""Name in use"", ""detail"": ""Filename already exists in this folder."" } ] }"
Response.End

I referred to https://jsonapi.org/examples/ to construct my sample error but it didn't change anything. How do I trigger the catch?

In response to the first comment this is the Fetch code:

          fetch('/dofs.asp?action=rename&src=' + strSrc + '&dest=' + strDest)
            .then(response => response.json())
            .then(data => { 
              $('#pi' + citem + ' .pimage-title').attr('title', nname)
              $('#pi' + citem + ' .pimage-title').html(nname)
            })
            .catch(error => { 
              console.log('error:' + error.message) 
            })
            .finally(function() {
              $('#pi' + citem + ' .pimage-title').css('color', 'unset')
              $('#frename').attr('tabindex', '90');
              $('#frename').css('display', 'none')
              renaming = false
            })
user692942
  • 16,398
  • 7
  • 76
  • 175
clubside
  • 33
  • 1
  • 4
  • Why `409` and not `400`? Also, can you share the AJAX call, are you using jQuery for example? – user692942 Jun 11 '20 at 22:33
  • I updated the question to show the Fetch code. There is legacy jQuery that deals with updating the page that I didn't want to touch, but the actual call is pure JavaScript. – clubside Jun 12 '20 at 00:05
  • It’s nothing to do with the Classic ASP the problem lies in the assumption that the JavaScript `fetch()` call would trigger the catch from an HTTP error. The duplicate makes it clear this is not the case. – user692942 Jun 12 '20 at 07:50

0 Answers0