ስህተቶች

9

የተተረጎመው መጠን

በዚህ ምዕራፍ:

  • የተሻለ የስህትቶች እና መልዕክቶች ማቀረቢያ ይፍጠሩ።
  • እንዴት `Template.rendered` ተጠቅመው ኣንድ ተጠቃሚ ስህተት ማየቱን ማወቅ እንደሚችሉ ይማሩ።
  • ስህተቶች ኣንዴ ብቻ እንዲታዩ የመንገድ መፈለጊያ ማጣሪያዎች ይጠቀሙ።
  • ////

    ////

    ስለቅርብ ኣካባቢ ስብስቦች መግቢያ

    ////

    ////

    ////

    ////

    // Local (client-only) collection
    Errors = new Meteor.Collection(null);
    
    client/helpers/errors.js

    ////

    throwError = function(message) {
      Errors.insert({message: message})
    }
    
    client/helpers/errors.js

    ////

    ስህተቶችን ማሳየት

    ////

    <template name="layout">
      <div class="container">
        {{> header}}
        {{> errors}}
        <div id="main" class="row-fluid">
          {{yield}}
        </div>
      </div>
    </template>
    
    client/views/application/layout.html

    ////

    <template name="errors">
      <div class="errors row-fluid">
        {{#each errors}}
          {{> error}}
        {{/each}}
      </div>
    </template>
    
    <template name="error">
      <div class="alert alert-error">
        <button type="button" class="close" data-dismiss="alert">&times;</button>
        {{message}}
      </div>
    </template>
    
    client/views/includes/errors.html

    መንታ ቅንብር ደንቦች

    ////

    ////

    ////

    Template.errors.helpers({
      errors: function() {
        return Errors.find();
      }
    });
    
    client/views/includes/errors.js

    ኣከማች 9-1

    Basic error reporting.

    ስህተቶችን መፍጠር

    ////

    ////

    Template.postSubmit.events({
      'submit form': function(e) {
        e.preventDefault();
    
        var post = {
          url: $(e.target).find('[name=url]').val(),
          title: $(e.target).find('[name=title]').val(),
          message: $(e.target).find('[name=message]').val()
        }
    
        Meteor.call('post', post, function(error, id) {
          if (error) {
            // display the error to the user
            throwError(error.reason);
    
            if (error.error === 302)
              Router.go('postPage', {_id: error.details})
          } else {
            Router.go('postPage', {_id: id});
          }
        });
      }
    });
    
    client/views/posts/post_submit.js

    ኣከማች 9-2

    Actually use the error reporting.

    ////

    Triggering an error
    Triggering an error

    ስህተቶችን ማጥራት

    ////

    ////

    ////

    ////

    ////

    // Local (client-only) collection
    Errors = new Meteor.Collection(null);
    
    throwError = function(message) {
      Errors.insert({message: message, seen: false})
    }
    
    clearErrors = function() {
      Errors.remove({seen: true});
    }
    
    client/helpers/errors.js

    ////

    // ...
    
    Router.before(requireLogin, {only: 'postSubmit'})
    Router.before(function() { clearErrors() });
    
    lib/router.js

    ////

    ////

    ////

    ////

    ////

    Template.errors.helpers({
      errors: function() {
        return Errors.find();
      }
    });
    
    Template.error.rendered = function() {
      var error = this.data;
      Meteor.defer(function() {
        Errors.update(error._id, {$set: {seen: true}});
      });
    };
    
    client/views/includes/errors.js

    ኣከማች 9-3

    Monitor which errors have been seen, and clear on routing.

    ////

    ////

    rendered መልሶ-ጥሪ

    ////

    ////